Tuesday, 28 April 2009

Biztalk Testing tools


Unit and Functional Testing
Microsoft Visual Studio® Team Suite Testing Tools
Used for unit testing .NET code. For more information about the testing tools that are integrated into Visual Studio 2005 Team System see "Visual Studio 2005 Team System: Enabling Better Software Through Better Testing" at http://go.microsoft.com/fwlink/?LinkId=102208.

BizUnit
A framework designed for automated testing of BizTalk solutions.
Use of this tool is not supported by Microsoft, and Microsoft makes no guarantees about the suitability of this programs. Use of this program is entirely at your own risk.

NUnit
Used for unit testing .NET code.
Use of this tool is not supported by Microsoft, and Microsoft makes no guarantees about the suitability of this programs. Use of this program is entirely at your own risk.
For more information about NUnit, see http://go.microsoft.com/fwlink/?LinkID=47931

Performance Testing
Microsoft BizTalk LoadGen 2007 tool
Load generation tool used to run performance and stress tests against BizTalk Server.
For more information about the Microsoft BizTalk LoadGen 2007 tool, see http://go.microsoft.com/fwlink/?LinkId=59841.

Friday, 6 March 2009

How to remove NS0 from the Incoming or Outgoing Message of Biztalk

The concept is very simple , Just remove the TargetNamespace from your Incoming /Outgoing Message and maintain Unique Name for Root Element.

How to Remove TargetNamespace ?

Select your Schema level properties and Delete the TargetNamespace. It should be empty.

When you remove the Targetnamespace Message Type identifies your schema based on Root Name , meaning it would be a unique filed to identify the subscriber.

Complex Situations :

1) If two BizTalk Projects wants to keep similar XML Structure as incoming message , You have to change the Root Name.
2) If you want to use the schema as referenced Schemas which will not be useful.

If you look at a Message Type details in Database how BizTalk Stores internally, you can understand better. See the below image. The current scenario will store only the Root Element.

Message Type = TargetNameSpace#RootElement

Now you can Receive Incoming message as below format instead of with NS0
Same Rule apply for Outgoing message also.

but no guarantee that It performs correct action for all adapters. You need to experiment...

You can reach me @ raj.webjunky@yahoo.com





Monday, 23 February 2009

ParallelBranch- Scope Synchronized=True

ParallelBranch- Scope Synchronized=True – How to Skip execution of all branches ?
What is the purpose of using “Synchronized=Ture” at Scope Shape?
When ever you want to use a variable across the Parallel branches you need to set the property for each branch Scope Shape Synchronized=True. In other hand we can say , Sharing a variable across the branches.
Let say you declared a variable “vGlobalVariable” at Orchestration Level and you are trying to update/ Set the value in each/ one of the branch , then you may encounter the below error ( when Synchronized=False – its default property for Scope Shape)
Error :
'vGlobalVariable': if shared data is updated in a parallel then all references in every task must be in a synchronized or atomic scope.

To over come this error you need to set the Synchronized=True. Fine what is the next issue ?

When you set Synchronized=True then each branch will execute one after one, for example if you have 3 branches like Branch1, Branch2 and Branch3. Then BizTalk executes the each branch in same order 1 , 2 and 3.

Now I have error at Branch 2 and I am catching the Error at Branch 2 Exception Block. But I do not want to proceed for Branch 3. How do I control the execution of all branches?

“ I came up with simple logic, It could be a silly but it works well, The logic is Declare a Bool type variable at Orchestration (vFlag=Tue) level and set the value at Each Branch Exception Block.
Also Second Branch and 3rd Branch should have Decide Shape to Check the Condition. “

You can also check the below article from “Scott Colestock” – for more Experiments on Parallel Branch.
http://www.traceofthought.net/PermaLink,guid,e2e45c5b-e8f3-4c05-9c60-d6e5e1ec29b3.aspx

The Orchestration looks like below

If you have any issues , reach me @ raj.webjunky@yahoo.com


Monday, 9 February 2009

Add Additional SOAP Header while Publish Orchestration as Webservice

Last couple of days I was busy with documnetation work in my office and one of my friend request me to provide an example for how to add an additional Soap Header while publishing the orchestration as webservice. I just tried to provide a URL from google search, unfortunately I could not find any right answer. Then I started my new journey to prepare my own example.

I was trying to publish my Orchestration as Webservice and tried to add additional SOAP header ( provided option while publish). I created a new Property Schema and changed the Target Namespace as
http://schemas.microsoft.com/BizTalk/2003/SOAPHeader

But when I try to select the Schema while publishing in the Tool , I couldn’t find the schema from the list. I was surprised and recollected myself what I was doing wrong?. And as per my observations I found that Document schemas are in the list to add as Additional soap Header but not Property schemas.

But how this document schema can be treaded as SOAP Header ?? any guess ..?
Lets do a deep drive to and see how we can add additional soap header for your Published Webservice.

First step is to create normal Document Schema and Change Root Node as “AuthenticateSoapHeader”. And add two Field elements under root node like UserName , Password.
Create a Property Schema and Rename the Property1 element as “AuthenticateSoapHeader” and set the property Schema Base = “MessageContextPropertyBase” also the Target NameSpace as http://schemas.microsoft.com/BizTalk/2003/SOAPHeader.


For more details of creating SOAP Header Schema , refer the below link (Steps to Create Soap Header Schema)
http://rajwebjunky.blogspot.com/2009/01/how-to-send-custom-soap-headers-from.html

Lets try to understand the purpose of creating Property Schema : When ever you add Document schema as Additional SOAP header at publish tool BizTalk Creates an Soap header class with the root node of your Document Schema. In my Example AuthenticateSoapHeader is the Root node of my Document Schema.

If you look at the MessageContext Property of your Orchestration Instance for Incoming Message , It shows clearly that AuthenticateSoapHeader is one of the value sent along with incoming message as part of Soap header.

Now next step is to get the SoapHeader XML data and assign the value to Document Schema.
Write the below code at MessageAssignment Shape

// get SoapHeader Information from Context
vData= IncomingInvoiceMsg(SoapHeaderExposeOrch.AuthenticateSoapHeader);
//Load SoapHeader xml data and assing to Document Schema
vXmlObj= new System.Xml.XmlDocument();
vXmlObj.LoadXml(vData);

//Assign SoapHeadr XML to Document Schema
SoapHeaderMsg=vXmlObj;



reach me if you have any issues :
raj.webjunky@yahoo.com

Thursday, 15 January 2009

How to send Custom Soap Headers from BizTalk


Hi, I have been searching for an good article which shows the step by step development approach for sending a Custom Soap Headers from Biztalk. I found a couple of Microsoft blogs but its not very clear to me.

I just started my invention to find the right direction to accomplish this task today. I thought this would a help others to work with custom soap adapters.

The first Step is to develop an Webservice which had an additional SOAP header to the Webmethod. I hope you are expert in writing .net code to build an simple Webmethod.Here is my sample WebMethod and custom Soap header.

Now lets start work on Biztalk Part

First Step is to create a Similar Soap Header Property Schema at biztalk and set the couple of property to make use of Custom Soap header. How you are going to achieve this?
Add webreference to your Biztalk Application. You can find the Reference.XSD Schema with custSoap header.

Steps to Create Soap Header Schema:
Create a Property Schema and rename to any(not necessary to rename) Just to keep this schema as more understandable. I renamed it as SoapHeader.xsd
Rename the “Property1” element to your Custom soap Header Class name and set the properties as mentioned below.
Ex: In my above .net Code my Soap header class name is “CustAuthHeader”
Schema property:
TargetNamespace=http://schemas.microsoft.com/BizTalk/2003/SOAPHeader
CustAuthHeader Property :
PropertySchemaBase = MessageContextPropertyBase


Assign SoapHeader Property values at Orchestration level :
As soon as you add web reference you can find Reference.xsd file which contain the SoapHeader elements. Here you have 2 options
  1. You can use Reference.XSD schema to send the UserName, Password
If you don’t find Reference.xsd then Create your Own schema and maintain Rootnode same as SoapHeader Class name and Input params as Elements.

Here I am using Reference.xsd schema to test this sample.
Before you call webMethod you need to pass the Soap Headers to the WebService Request. The orchestration Steps are

  1. collect the Input values from the Inbound Schema
  2. map the InputSchema to Reference.xsd Schema
  3. Assign Reference Schema Values to SoapHeader Property
  4. Call Webservice and get Response

Here step1, 2 and 4 is easy. What about the step 3 ? what you need to write at Assignment Shape ?
Here is the code
vxmlObj = new System.Xml.XmlDocument();
vxmlObj= WsReferenceMsg;
SoapHeaderWsRequestMsg(SOAPHeaderTest.CustAuthHeader)=vxmlObj.InnerXml.ToString();
Note: SOAPHeaderTest.CustAuthHeaderĂ  ProjectName.YourPropertySchemaRoot element.

Your final Orchestration should look like above image.
You can reach me at : raj.webjunky@yahoo.com

Monday, 5 January 2009

Custom Soap Exception Detail Propty -Work with BizTalk

How to make use of Custom SOAP error Detail property in BizTalk ?
Today I start this artical with showing a property of Soap Exception. Just have a look at the below image. Have you ever played around with Detail Propery provided by SoapException? If your anwer is "Yes" then jump to Biztalk part below the Webservice code and see how to handle the Detail property at biztalk level. Otherwise check the below code for detailed programming for Custom Soap Exceptions. ( Build a Detail property using Csharp Code).
.

I have written a simple webservice (webmethod) which accepts two input parameters and check the authentication. If success then returns the Bool value of "True" else raise the Cusom Soap Error Message.

WebService Code
[WebMethod]
public bool CheckAuthentication(string UserName , string Password)
{ if (UserName == "TestUser" && Password == "TestPwd")
{ return true; }
else
{
throw RaiseCustomSoapError("AuthenticationCheck","","101","User is not Authorize person to access this site" "CustomSOAPException");
}
}
________________________________________________________________________________________________________
public SoapException RaiseCustomSoapError(string NameofActor, string wsNamespace, string errNumber,string errMsg, string errSource)
{
XmlQualifiedName tmpfaultCode = null;
tmpfaultCode = SoapException.ClientFaultCode;

XmlDocument xmlDoc = new XmlDocument();
XmlNode rootNode = xmlDoc.CreateNode(XmlNodeType.Element,SoapException.DetailElementName.Name,SoapException.DetailElementName.Namespace);
XmlNode errorNode1 = xmlDoc.CreateNode(XmlNodeType.Element, "Errors", wsNamespace);
XmlNode errorNode = xmlDoc.CreateNode(XmlNodeType.Element, "Error",wsNamespace);
errorNode1.AppendChild(errorNode);

XmlNode errNumberNode = xmlDoc.CreateNode(XmlNodeType.Element, "ErrorNumber", wsNamespace);
errNumberNode.InnerText = errNumber;

XmlNode errMsgeNode = xmlDoc.CreateNode(XmlNodeType.Element, "ErrorMessage", wsNamespace);
errMsgeNode.InnerText = errMsg;

XmlNode errSourceNode = xmlDoc.CreateNode(XmlNodeType.Element, "ErrorSource", wsNamespace);
errSourceNode.InnerText = errSource;

errorNode.AppendChild(errNumberNode);
errorNode.AppendChild(errMsgeNode);
errorNode.AppendChild(errSourceNode);
rootNode.AppendChild(errorNode1);

//Constructing the exception
SoapException soapEx = new SoapException(errMsg, tmpfaultCode, NameofActor, rootNode);
return soapEx;
}
When you select soapEx.Detail property will retun the XML Structure of Error Details as mentioned in below format.
Custom Error Message Structure



BizTalk Code
Summary of Orchestration Flow : BizTalk receives the Inbound XML File which has username,password and Sends the same to Webservice method (CheckAuthentication) "Request"
If the UserName and password is valid then Wesbservice return the Success status of "True" value and you need to build the output Message and send to Destination Location.
Incase of Failed Authentication Webservice Throws Custom SOAP Exception. Biztalk will pick this Exceptions at SOAP Exception block (System.Web.Services.Protocols.SoapException) using Detail Property.

Inbound and Outbound Schemas:



Orchestration Flow


Write the below code at Assign Error Detail ( Assignment Shape) Code

vErrDetails = soapEX.Detail.OuterXml.ToString();
vXmlObj = new System.Xml.XmlDocument();
vXmlObj.LoadXml(vErrDetails);
GenMsg = vXmlObj;

vXmlObj2= new System.Xml.XmlDocument();
vXmlObj2.LoadXml(" Your generated output Schema structure");

OutputMsg = vXmlObj2;
xpath(OutputMsg,"//Errors") = xpath(GenMsg,"//Error");



For success Output message Error node would be empty and for the Failure (Custom Soap Error Detail property message) Error node filled with details.


you can reach me at raj.webjunky@yahoo.com