Tuesday, October 26, 2010

BizTalk Adapter Pack 2.0 Migration Wizard – SAP IDOCs

http://kentweare.blogspot.com/2009/12/biztalk-adapter-pack-20-migration.html

Sunday, October 17, 2010

Zombie

• What is a zombie?
A zombie message is a message that was routed to a running orchestration from the messagebox and was "in flight" when the orchestration ended. An "in flight" message is a message that has been routed to a service instance and so is in a messagebox queue destined for the service instance. Since the message can no longer be consumed by the subscribing orchestration instance, the message is suspended and marked with a ServiceInstance/State value of "Suspended (Non-resumable)".
A zombie service instance is an instance of an orchestration which has completed while a message that was routed to the orchestration instance from the messagebox was still "in flight". Since the orchestration instance has ended, it cannot consume the "in flight" messages and so is suspended and marked with a ServiceInstance/State value of "Suspended (Non-resumable)".
The occurrence of zombies typically falls into one of the following categories:
1. Terminate control messages – The orchestration engine allows the use of control messages to cancel all currently running work in a specific orchestration instance. Since the control message immediately halts the running orchestration, zombie instances are not unexpected. A number of Human Workflow related designs tend to use this mechanism as well as some other designs.
2. Parallel listen receives – In this scenario the service instance waits for 1 of n messages and when it receives certain messages it does some work and terminates. If messages are received on a parallel branch just as the service instance is terminating, zombies are created.
3. Sequential convoys with non-deterministic endpoints – In this scenario, a master orchestration schedule is designed to handle all messages of a certain type in order to meet some type of system design requirement. These design requirements may include ordered delivery, resource dispenser, and batching. For this scenario, the tendency is to define a while loop surrounding a listen with one branch having a receive and the other having a delay shape followed by some construct which sets some variable to indicate that the while loop should stop. This is non-deterministic since the delay could be triggered, but a message could still be delivered. Non-deterministic endpoints like this are prone to generating zombies.
When a zombie service instance is suspended in Microsoft BizTalk Server 2006 the following error message is generated:
Copy
0xC0C01B4C The instance completed without consuming all of its messages. The instance and its

Tuesday, October 12, 2010

Test the biztalk application with same folder

A really simple tip that is great to use when building demos and proof of concepts using the file adapter.

1. Create one folder (docs) and place all your test files there.

2. Configure the receive location to use the docs folder and “Copy*.xml” as the filter (for Server 2008, Vista and 7 use “*Copy*.xml”

3. Configure all your send ports to send to the docs folder with filenames like “Order_%MessageID%.xml”.

When you test, select the file and use CTRL+C, CTRL+V to create a copy.

You can then test your application from one folder.

Unit Testing In Biztalk 2009

Deployment property page of a BizTalk project. The following screenshot shows this project setting accessed from Project Designer when we right-click a project and click the Properties.




Screenshot of the Deployment tab in Project Designer exposing the Enable Unit Testing project property.


This feature allows us to create unit tests for schemas, maps, and pipelines.

When this feature is enabled and the project rebuilt, the artifact classes will be derived from the following base classes to support unit testing.

Artifact type
Base class
Schema
Microsoft.BizTalk.TestTools.Schema.TestableSchemaBase
Map
Microsoft.BizTalk.TestTools.Mapper.TestableMapBase
Pipeline
Microsoft.BizTalk.TestTools.Pipeline.TestablePipelineBase




Using the Unit Testing Feature with Schemas

This topic demonstrates how to use the unit testing feature to add a unit test for the schemas.

Testing Schemas
Schemas can be unit tested by using them to validate instance messages. To create Unit Test, we need to select Test->New Test from the Visual Studio Menu. This will bring up a dialog box where we will select Unit Test Wizard.


We have to enter a project name for the unit testing project when we are prompted for it.


After the Create button is pressed, we can see “Create Unit Tests” dialog box. We have to choose the Filter drop down list and select “Display Base Types”. Then we need to expand the Schemas Project, Schemas.SimpleRequest, Bases & Interfaces and select “Microsoft.BizTalk.TestTools.Schemas.TestableSchemaBase”.


Pressing OK button will create unit tests for each selected schema in the schemas in the project. It will also set all the necessary project references. We can validate XML as well as flat files.



The following code will be generated for the Test Method. We will need to set references to an input instance filename to validate the test instance.

[TestMethod()]
public void ValidateInstanceTestWithValidMessage()
{
TestableSchemaBase target = new SimpleRequest();
string inputInstanceFilename = @" ValidSimpleRequest.xml";
OutputInstanceType inputType = new OutputInstanceType();
inputType = OutputInstanceType.XML;
bool expected = true;
bool actual;
actual = target.ValidateInstance(inputInstanceFilename, inputType);
Assert.AreEqual(expected, actual);
}


The Solution Items file LocalTestRun.testrunconfig is to be opened. We need to select the Deployment screen and add the directory that contains all the test data and schemas that will be used during unit testing. This will allow us to use relative paths in our unit tests.









Using the Unit Testing Feature with Maps

Maps can be tested by passing a test input instance to the map and validating that output message has been correctly transformed. We have to follow the exact same steps to generate a Unit Test for Map as it is for creating Unit Test for a Schema. In this case we have to select the class “Microsoft.BizTalk.TestTools.Mapper.TestableMapBase”.
But Multi-Input maps cannot be unit tested in this version of BizTalk.
The generated Unit Test will have a method where we just need to update information about the input and output message instances.

[TestMethod()]
public void TestMapAddTest()
{
TestableMapBase target = new SimpleRequest_To_SimpleResponse();
string inputInstanceFilename = @" AddSimpleRequest.xml";
InputInstanceType inputType = new InputInstanceType();
inputType = InputInstanceType.Xml;
string outputInstanceFilename = @"AddSimpleResponse.xml";
OutputInstanceType outputType = new OutputInstanceType();
outputType = OutputInstanceType.XML;
target.TestMap(inputInstanceFilename,
inputType, outputInstanceFilename, outputType);
XmlDocument output = new XmlDocument();
output.Load(outputInstanceFilename);
Assert.AreEqual("20", output.SelectSingleNode("/*[local-name()='SimpleResponse' and namespace-uri()='http://Schemas.SimpleResponse']/*[local-name()='Result' and namespace-uri()='http://Schemas.SimpleResponse']").InnerText);
}

Using the Unit Testing Feature with Pipelines

Both send and receive pipelines can be unit tested. Pipelines can be tested by passing a test input instance and schema to the pipeline. We have to follow the exact same steps to generate a Unit Test for Pipeline as it is done for creating Unit Test for a Schema. In this case we have to select “Microsoft.BizTalk.TestTools.Mapper.TestableReceivePipeline” for unit testing a receive pipeline and “Microsoft.BizTalk.TestTools.Mapper.TestableSendPipeline” for unit testing a send pipeline.

We have to customize the generated unit testing code with additional details about test instance messages and schemas.
Unit Test code to test receive and send pipeline is shown below.

[TestMethod()]
public void TestReceivePipelineTest()
{
TestableReceivePipeline target = new FFRcvSampleFile();
StringCollection documents = new StringCollection();
documents.Add(@"Sampe ASCII.txt");
StringCollection parts = new StringCollection();
Dictionary schemas = new Dictionary();
schemas.Add("Schemas.SampleSchema", @"SampleSchema.xsd");
target.TestPipeline(documents, parts, schemas);
}


[TestMethod()]
public void TestSendPipelineTest()
{
TestableSendPipeline target = new FFSendSampleFile();
StringCollection documents = new StringCollection();
documents.Add(@"SampleSchema.xml");
StringCollection parts = new StringCollection();
Dictionary schemas = new Dictionary();
schemas.Add("Schemas.SampleSchema", @"SampleSchema.xsd");
target.TestPipeline(documents, parts, schemas);
}


Known Issues

· The Unit testing feature for maps currently does not support multiple map inputs.
· When we are testing maps, output Instance file name cannot be null or empty.
· BizTalk SDK needs to be deployed to the machine running the pipeline unit tests.


Conclusion

Unit testing is a best practice when it comes to application development.
Until the release of BizTalk 2009 we had to rely on unit testing frameworks like BizUnit and Pipeline Testing Library to test BizTalk components. Having native support for testing Schemas, Maps and Pipelines makes unit testing easier.
By driving development with automated tests any developer can write reliable, bug-free code no matter what its level of complexity.





References
http://www.msdn.com

Wednesday, October 6, 2010

BizTalk WCF Web Service Over SSL

1 . Expose a BizTalk WCF Web Service using BizTalk WCF Service Publishing
Wizard tool.
It creates one WCF web service in IIS and another one is Receive Location in BizTalk.
2 . Changes required in Web.Config of WCF Web Service.
Go to the web.config file by navigating from WCF Web Service in IIS.
a . Configure BizTalk Receive Location

receiveLocationName="WcfService_BizTalkAccountDataWcfService/AcountDataService"
publicBaseAddress=https://<>:9090/ />

b . HttpsGetEnable should be true

c . Enable HttpsMexendpoint
binding="mexHttpsBinding" bindingConfiguration=""
contract="IMetadataExchange" />
3 . Changes required in BizTalk ReceiveLocation configuration.
Go to the Biztalk ReceiveLocation that will be created by Wizard in first step.
Click on the configuration button (here transport type may be WCF-BasicHttp or
WCF- WSHttp).Next Click on Security tab of Transport Property, then change the below
configuration.
Security Mode: Transport
Transport clint credential type : None
4. Changes required in IIS
a . Set the Application Pool for the WCF Web Service.
Select your WCF Web Service from IIS and click on Advanced Settings from
Action pane. Create a new application pool and select here, otherwise you can give
BAMAppPool temporarly.
ApplicationPool – BAMAppPool (example)
b . Create a Self signed Certificate
i. Go to IIS and click on the Top node then Click on the Server Certificates from
central panel.
ii. Click on the Create a Self Signed Certificate from Action panel.
iii. Enter the name and click ok.
c . Add https with port and certificate.
i. Select Default Web Sites in IIS then click on bindings option from Actions panel
(it will be right panel of the IIS).
ii. Click on the Add button on Site Bindings pop up.
iii. Select following setting on Add site bindings.
Type: Https
Port: 9090 (Use the same port what you used in web.config – look at the2.a
section above)
SSL Certificate: Select a certificate you created in 4.a section above.
d . Enable SSL for you WCF web Service.
i. Click on your WCF Web Service inside IIS.
ii. Then Click on SSL Settings from central panel. Next Check the SSL
Required checkbox and Select the Accept radio button for Clint Certificates.
5. Restart the IIS using IISReset command and enable the BizTalk ReceiveLocation then try
to browse the URL. It will show the WSDL file without error.
Reference URL - http://rocksolidknowledge.com/Screencasts.mvc/Watch?video=WCFSSL.wmv

Orchestration Debug with System.Diagnostics.Debug and Parallel shapes in orchestration

Orchestration Debug with System.Diagnostics.Debug and Parallel shapes in orchestration

In this post I want to show alternate method for Debug and demonstrate how Parallel shape
works in orchestration.

1. Create new orchestration
2. Create first receive port
3. Insert Parallel Actions shape
4. Add to shape 2 branches
5. Add 8 Expressions

So your orchestration should look like
6. edit each expression shape
Expression_1 :
System.Diagnostics.Debug.WriteLine("Exp1");

Expression_2 :
System.Diagnostics.Debug.WriteLine("Exp2");

Expression_3 :
System.Diagnostics.Debug.WriteLine("Exp3");

Expression_4 :
System.Diagnostics.Debug.WriteLine("Exp4");

================

Expression_8 :
System.Diagnostics.Debug.WriteLine("Exp8");


Download DebugView Utility from
great tool by Mark Russinovich

Create a simple xml which will start orchestration


Start debug view
Enable Capture Global Win32, Enable Verbose Kernel Output
Start orchestration
and check for output !


Same trick you can use in your Window applications, Windows services and WPF applications.

BizTalk Orchestration debug

BizTalk Orchestration debug

You can debug your orchestration using Visual Studio by attaching it to BTSNTSvc.exe processes. The orchestration will be debugged without break point if it has Exception,
in this case you will not need to setup a break point, like any desktop application which you run in debug mode.
The engine will generate C# file for you were you can details of the exception.

In this post I want to show how to debug an orchestration setting a break point

I will create an orchestration which will throw an exception when dividing by 0 (Zero)

Create a simple schema where you will pass 2 numbers
and another schema with 1 parameter which will hold division result.

All element should be decimal and distinguished

1. Create Receive port in orchestration
2. Create Scope
3. Add Construct message to Scope
4. Add Message assignment to constructor
5. Create Send port

Edit expression for assignment:

Variable_1.LoadXml(@"14.4 ");
MessageOut = Variable_1;
MessageOut.Result = (MessageIn.x / MessageIn.y);

where Variable_1 is System.Xml.XmlDocument variable in the Scope
Change namespace and parameters if needed.

At the end your orchestration should look like
Now create two file adapters to receive parameters and send the result
Deploy BizTalk project and bind orchestration ports

For the first time input simple right numbers for x and y
Check the output that result is OK.

then insert 0(Zero) for y which will produce Exception in orchestration
In Event Viewer you will have the exception description

xlang/s engine event log entry: Uncaught exception (see the 'inner exception' below) has suspended an instance of service 'OrchDebug.Division(6ec96fde-7908-1b3e-f21d-244ab1fe40fa)'.
The service instance will remain suspended until administratively resumed or terminated.

Open Group Hub in BizTalk Management Console

check for suspended messages you will see there new Resumable message

open that message in list and right click on it

Start debugger

in this case you can see the shapes and setup a break point.

Then just attach your visual studio debugger to BTSNTScv.exe
and debug it like a windows server or Web application

after attaching to debugger put new file in receive directory and check your visual studio, it will debug your orchestration.

biztalk server 2009 and wcf sql adapter

http://geekswithblogs.net/martinabbott/archive/2009/06/03/biztalk-server-2009-and-wcf-sql-adapter.aspx

How to backup BizTalk Server

How to backup BizTalk Server

All settings of BizTalk Server are located in MS SQL Server
So it is enough to Backup SQL Server databases

1. Open SQL Server Management Studio
2. Expend SQL Server Agent
3. Open Jobs
4. Open properties of Backup BizTalk Server job
5. In Steps select Backup Full and press Edit
6. Set Destination to C:\BackupFolder
7. Click Next, go to MarkAndBackupLog
8. Set Destination to C:\Backupfolder
9. Click Next
10. Click Next
11. Right click on Backup BizTalk Server job
12. Select Start Job At Step
13. Click Start
14. Check if backup was successful


You can schedule backup job in properties of the Job

Exception handling in Orchestrations

Exception handling in Orchestrations

I am
At this post I would like to explain error handling in orchestrations and show how to make it with divide by zero exception.

1. first of all create new scope which will be the equivalent to tryin .NET
2. add expression to scope
3. set expression to
V = 6;
V = 5 / (6-V); // this line with throw divide by zero exception
where V is a decimal variable in orchestration
4. Right click on the scope and add exception block
5. Set
Exception Object Type to System.ArithmeticException
Exception Object Name to Ex
6. In exception block add Construct Message shape which will hold error description
7. Add Message Assignment shape to Construct Messageshape
8. Set assignment expression to
Message_3 = new System.Xml.XmlDocument();
Message_3.LoadXml(""+Ex.Message+"");
9. After Assignment shape insert Send shape which will sendMessage_3 to any location (FILE) you would like


Message Box cleanup

Message Box cleanup

It is usually a very important task to clean up a BizTalk mseeage box during stress testing with large amount of messages. Below are the steps to clean up the message box in order to prepare for the new test.

1. Stop all BizTalk services

2. Type iisreset at command line to recycle IIS service

3. Execute the stored procedure bts_CleanupMsgbox on your message box database

4. Execute the stroed procedure bts_PurgeSubscriptions on your message box database

(if the above stored procedures can't be found, go to your BizTalk installation directory, under “Schema” folder, you can find all original scripts of these stored procedures)

5. Clean up the message box log by running the backup statement similar to below

backup log msgBoxDb to disk = 'yourbackupdirectory\yourbackupfile.bak' with init, stats = 5

6. Restart BizTalk services