Monday, November 17, 2008

Consuming And Publishing Web Services in BizTalk Server using SOAP and WCF Basic Http Adaptor

Consuming Web Services In BizTalk:

Steps for Consuming Web Services:

1) Add Web Reference, When you add a Web reference to your project, BizTalk creates an orchestration Web port type, Web message types, Reference.map (map file), Reference.odx (orchestration file), <WebService>.disco (discovery file), and <WebService>.wsdl (Web Service Description Language file) to your project.

Constructing Web Messages

When you add a Web reference, BizTalk automatically creates Web message types, which BizTalk creates based on the Web methods from the added Web service. You add a Web message to your orchestration, setting the message type to one of the Web message types.

Web messages types

Web message types are identical to a normal message type, except you cannot modify, rename or delete them. To delete a Web message type, you must remove the Web reference from your BizTalk project.

BizTalk creates one request and one response Web message type for each Web method in the added Web service. If the Web method is a one-way operation, BizTalk only creates a request Web message type. A request Web message type contains one message part for each input parameter of the Web method. A response Web message type contains one message part for the return value and one message part for each output parameter of the Web method.

Depending on the Web method parameter (input or output), BizTalk creates a Web message type from a primitive .NET type or a schema type. If the Web method parameter is a primitive .NET type, the message part uses a primitive .NET type. If the Web method parameter is a schema type, BizTalk adds the schema type to the BizTalk project as a schema in Reference.xsd. The schema is the basis for the message part. You can find Reference.xsd in the Web references folder.

Alternatively, you can create both primitive and schema .NET types by calling a .NET class. For more information on creating message types by using a .NET class, see Constructing Messages in User Code.

Web messages

Web messages are the messages you use when you consume (call) a Web service. You add a Web message to an orchestration the same way that you add a regular message, except that you set the message type to one of the Web message types that BizTalk created when you added a Web reference.

Message parts

After you create the Web message, you construct the individual message parts. If your message part uses a primitive .NET type, you use a Message Assignment shape. If your message part uses a schema type, you use a Transform shape.

Determining a Web Message Part Type

You can determine if a Web message part type is a primitive .NET type or a schema type by using the Properties window for a given Web message type.

To determine a Web message part type

1.       With an orchestration open, on the View menu, click Other Windows, and then click Orchestration View.

2.       Expand the Multi-part Message Types node, and then expand a Web message type.

3.       Select a message part.

A Web message part signature that begins as <project default namespace>.<Web reference name>.Reference.<schema root>is a schema type. The <schema root> part of the type is the root element of the Web reference schema that constructs the Web message part. Otherwise, the message part signature is a primitive .NET type such as System.String or System.Int32.

Constructing a Web Message Part from a Primitive .NET Type

You create a Web message part from a primitive .NET type by using a Message Assignment shape. Alternatively, you can create a Web message part from a primitive .NET type by using a .NET helper class to set the parts

ItemAvailRequestInstance.Item_ID = "This is Item_ID.";

Constructing a Web Message Part from a Schema Type

You create a Web message part from a schema type by using a Transform shape.

You are saying there will be no WSE 3.0 adapter for BizTalk. Why?

WCF will be released soon after BizTalk 2006 is released. The WCF adapter for BizTalk will be wire compatible with both WSE 3.0 and WCF callers and endpoints. Once released, the WCF adapter for BizTalk Server will provide a single solution for WSE 2 and 3 standards. In the meantime, there are partners that provide WSE 3 adapters today.

 

 

BizTalk 2006 R2 - consume an .ASMX webservice using WCF-BasicHttp adapter

 

Normally when we need to consume a .asmx web service in BizTalk 2004/2006 (NOT R2) inside an orchestration, we add a web reference, which will create all the multi-part message and web port type required to consume the orchestration. You construct the orchestration and configure the SOAP adapter in the send port to consume the web service. I suppose that's the normal route any BizTalk developer will take when you are put under a circumstance to consume an .asmx webservice using WCF-BasicHttp adapter.

But when you are going to use the WCF-BasicHttp adapter, "Add Web Reference" is not going to work, and we need to take advantage of the hidden "Consume WCF Service" wizard, which comes as part of BizTalk 2006 R2. The wizard will generate required schemas, multi-part messages, orchestration port types, and also binding files for both basicHttp and custom binding. I'll put the steps here to consume a basic .asmx webservice in BizTalk 2006 R2 with WCF-BasicHttp adapter.

The sample webservice we are going to use contains a very simple webmethod as shown below.

[WebMethod]
public string ConcatName(string firstName, string lastName)
{
return firstName + " " + lastName;
}

The below walk-through is based on the sample webservice, which comes as part of the download.

1.      Create a blank BizTalk Project

2.      Right-Click on the project and select Add->Add Generated Items->Consume WCF Service

3.      Select the option "Metadata file (WSDL and XSD)", Click "Next"

4.     

5.      Open an instance of a browser and navigate to your ".asmx?WSDL" file and save it somewhere in your harddrive (Example: c:\Service.wsdl).

6.      Click on the "Add" button (next step in the wizard after the one shown above), browse to the .WSDL file you saved in Step 4, Click "Next" (Accept defaults), Click "Import" and then Click "Finish" to complete the wizard.

7.      Once you click "Finish" the following files will be added to your project (File name will depend on the name of the .WSDL file you selected)
Service.BindingInfo.xml
Service.odx
Service_Custom.BindingInfo.xml
Service.tempuri_org.xsd

8.      Open the Service.odx file, inside the orchestration view create 2 messages as shown below
WSRequest - Multi-part Message Type - ConsumeWebService.ConcatNameSoapIn
WSResponse - Multi-part Message Type - ConsumeWebService.ConcatNameSoapOut

9.      Right-Click on the orchestration "Port Surface", Click "Next", In the port properties page Click "Next", In the "Select a Port Type" page select "Use an existing Port Type" and select "ConsumeWebService.ServiceSoap", In port binding page select "I'll be sending a request and receiving a response." for port direction and "Specify later" for port binding. Click "Next" and then "Finish".

10.  Construct an orchestration as shown in the below figure
Receive_1 -> Activate=true, Message= WSRequest
Send_1 -> Message = WSRequest
Receive_2 -> Message = WSResponse
Send_2 -> Message = WSResponse

11. 

12.  I created a FILE Receive and FILE Send (Specify Now) port binding for port_2 and port_3

13.  Assign a key file to the project and set the "Application Name" to "ConsumeWebService". Build and Deploy the project.
Open BizTalk Administration Console, Right-Click on the application and select "Import Binding". Browse to the 
auto generated binding file "Service.BindingInfo.xml" and select it.

14.  Bind your Orchestration to the correct ports and host. For the .asmx webservice logical port, select the auto generated "WcfSendPort_Service_ServiceSoap". (Start the application)

15.  Create a sample message by right-clicking on "Service_tempuri_org.xsd" file and clicking "Generate Instance". Drop the message in the folder you configured for port_2 in the orchestration, you should see the output result in folder you configured for port_3 in your orchestration.

 

3 comments:

Anonymous said...

Who knows where to download XRumer 5.0 Palladium?
Help, please. All recommend this program to effectively advertise on the Internet, this is the best program!

Anonymous said...

Good Post..

Anonymous said...

I am not able to see the images. Can you fix this?