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.
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
- Create a blank BizTalk Project
- Right-Click on the project and select Add->Add Generated Items->Consume WCF Service
- Select the option “Metadata file (WSDL and XSD)“, Click “Next”
- Open an instance of a browser and navigate to your “.asmx?WSDL” file and save it somewhere in your harddrive (Example: c:Service.wsdl).
- 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.
- 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)
- 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
- 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”.
- 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
Download the sample here
- I created a FILE Receive and FILE Send (Specify Now) port binding for port_2 and port_3
- 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.
- 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)
- 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.