Thursday, 11 December 2008

BizTalk Consumes Complex Data Type (Class/Object) Web Service

I have been trying to find an article that shows some light on how to consume a Web Service that returns Complex Data Type like Class / Object. At last I tried with small example which gave me good “Beep” to do a further investigation for Complex Data Types with Web Service.Here is my Class which I am going to use it as Complex data Type in Webservice.
Here is my Class which I am going to use it as Complex data Type in Webservice.

Create a C# WebService and create an Web Method that accepts 3 input parameters lime Employee ID , Employee Name and Employee JOB, also the web method returns the EMPLOYEE class as a datatype. Below is the Sample Code.


Now I am trying to Call this Webservice from the BizTalk , The challenge work is how Biztalk Returns the Employee Class to the destination ??

Schemas and Maps

Add a webreference to the BizTalk Application. Once you add web reference You can find a Reference.XSD file under your webReference. Here I renamed my webreference from localhost to “BTSlocalhost
Solution

Create a InputSchema that contain EmpID, Name, Job fields. The Structure looks like below


Create an ouput file with 3 fields as shown below

Now the Map is not between Input and Output Schema. Confused ??? , yes Here input schema used to send the data to the Webservice and that webservice returns the Employee Class as a Datatype. So the Reference.XSD is used as Source Schema and destination schema is ouput schema.
The Reference Schema contains the Employee Class and which creates a “Result” Method for Response object.


Orchestration

Create Message
Ws1_Resquest
= WebServiceTest.BTSLocalhost.AbcBTSWebServiceTest_. TestEmployee_request
Ws1_ResponseMsg = WebServiceTest.BTSLocalhost.AbcBTSWebServiceTest_.TestEmployee_response
Apart from this BizTalk creates an additional method called “Result” automacially.
Ws1_ResponseMsg. TestEmployeeResult
You need construct the TestEmployeeResult Message in your message Assignment shape.

Generate an Instance for your Reference.xsd and Load that XML file from your Message assignment shape and assign to “Ws1_ResponseMsg.TestEmployeeResult”

Apparently assign the input values to Webservice Method input parameters by extracting the values using xpath.
Ex: Ws1_Resquest.ename= xpath(InputMsg, string(“your xpath ”));



Now you need to use the Result Object in Transform Shape to assign the values to Output Schema.

Finally your Orchestration Looks like below.

Test your Application with sample File
Let me know If you have any issues reach me @ raj.webjunky@yahoo.com

1 comment: