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

Posted at: 5/31/2007 at 7:40 PM by saravana

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. Open an instance of a browser and navigate to your ".asmx?WSDL" file and save it somewhere in your harddrive (Example: c:\Service.wsdl).
  5. 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.
  6. 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
  7. 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
  8. 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".
  9. 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
  10. I created a FILE Receive and FILE Send (Specify Now) port binding for port_2 and port_3
  11. 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.
  12. 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)
  13. 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.

Download the sample here

Nandri!

Saravana

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags: | |  Categories: BizTalk 2006 R2 | BizTalk General
Actions: Email this article Email | Kick it! | DZone it! | Save to del.icio.us | Technorati Links
Post Information: Permanent LinkPermalink | CommentsComments(11) | Comments RSS

Comments

Monday, August 27, 2007 2:45 PM
Anonymous
Anonymous
Hi Saravana,

do you know how to use the "hidden Consume WCF Service" without R2? Smile

Thanks,
Christoph
Friday, November 09, 2007 10:27 AM
john
john
Thanks for the great info. I am however not able to get my app to function. I get this message...
The adapter failed to transmit message going to send port "WcfSendPort_BillerRateReadySCService_BasicHttpBinding_IBillerRateReadySC" with URL "http://localhost:8000/BillerRateReady/IBillerRateReadySC.svc". It will be retransmitted after the retry interval specified for this Send Port. Details:"System.ServiceModel.FaultException: ...

</BtsActionMapping>' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, ...Microsoft.BizTalk.Adapter.Wcf.Runtime.WcfClient`2.RequestCallback(IAsyncResult result)".

For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.

Any help would be much appreciated!
Friday, November 09, 2007 11:39 AM
Saravana Kumar
On the WCF adapter configuration there will be option to specify Action (that's same as SOAPAction we used in .asmx based web services). You can either specify a single action or set of actions/binding with help of an xml file. make sure you are providing the correct Action (SOAPAction) in the send port config.
Friday, November 09, 2007 2:21 PM
John
John
Thanks for your quick response...

As I imported the generated bindings the Send Port was all configured. The SOAP Action(s) appear to be correct....

...BtsActionMapping xmlns:xsi="http://www.w3.org/2001/XMLSchema" rel="nofollow">http://www.w3.org/2001/XMLSchema" rel="nofollow">http://www.w3.org/2001/XMLSchema" rel="nofollow">http://www.w3.org/2001/XMLSchema-instance" rel="nofollow">http://www.w3.org/2001/XMLSchema" rel="nofollow">http://www.w3.org/2001/XMLSchema" rel="nofollow">http://www.w3.org/2001/XMLSchema" rel="nofollow">http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" rel="nofollow">http://www.w3.org/2001/XMLSchema" rel="nofollow">http://www.w3.org/2001/XMLSchema" rel="nofollow">http://www.w3.org/2001/XMLSchema" ...
..Operation Name="AddRateReadyFileRecord" Action="http://tempuri.org/AddRateReadyFileRecord" rel="nofollow">http://tempuri.org/AddRateReadyFileRecord" ...
../BtsActionMapping..

The message being held looks ok.

The exception in the event log is;

The adapter failed to transmit message going to send port "WcfSendPort_Service_ServiceSoap" with URL "http://localhost:81/RateReadyService/Service.asmx". It will be retransmitted after the retry interval specified for this Send Port. Details:"System.ServiceModel.FaultException: soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema" rel="nofollow">http://www.w3.org/2001/XMLSchema" rel="nofollow">http://www.w3.org/2001/XMLSchema" rel="nofollow">http://www.w3.org/2001/XMLSchema-instance" rel="nofollow">http://www.w3.org/2001/XMLSchema" rel="nofollow">http://www.w3.org/2001/XMLSchema" rel="nofollow">http://www.w3.org/2001/XMLSchema" rel="nofollow">http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" rel="nofollow">http://www.w3.org/2001/XMLSchema" rel="nofollow">http://www.w3.org/2001/XMLSchema" rel="nofollow">http://www.w3.org/2001/XMLSchema" soap:Body soap:Fault faultcode soap:Client faultcode faultstring System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: <BtsActionMapping xmlns:xsi="http://www.w3.org/2001/XMLSchema" rel="nofollow">http://www.w3.org/2001/XMLSchema" rel="nofollow">http://www.w3.org/2001/XMLSchema" rel="nofollow">http://www.w3.org/2001/XMLSchema-instance" rel="nofollow">http://www.w3.org/2001/XMLSchema" rel="nofollow">http://www.w3.org/2001/XMLSchema" rel="nofollow">http://www.w3.org/2001/XMLSchema" rel="nofollow">http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" rel="nofollow">http://www.w3.org/2001/XMLSchema" rel="nofollow">http://www.w3.org/2001/XMLSchema" rel="nofollow">http://www.w3.org/2001/XMLSchema">
<Operation Name="AddRateReadyFileRecord" Action="http://tempuri.org/AddRateReadyFileRecord" rel="nofollow">http://tempuri.org/AddRateReadyFileRecord" />
<Operation Name="AddRateReadyRecord" Action="http://tempuri.org/AddRateReadyRecord" />
<Operation Name="AddException" Action="http://tempuri.org/AddException" />
</BtsActionMapping>.
at System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest()
at System.Web.Services.Protocols.SoapServerProtocol.RouteRequest(SoapServerMessage message)
at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing) /faultstring detail / /soap:Fault /soap:Body /soap:Envelope at Microsoft.BizTalk.Adapter.Wcf.Runtime.WcfClient`2.RequestCallback(IAsyncResult result)".

For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.
Monday, November 12, 2007 4:19 PM
john
john
Issue resolved:

I had to add this attribute to my web service and all worked fine.
[SoapDocumentServiceAttribute(RoutingStyle = SoapServiceRoutingStyle.RequestElement)]
yassers.com/content/book/chapters/AppendixB.htm

Next Issue:
How do I access the Response fields. In an expression editor I simply get the WSResponseMsg.Parameters.
Tuesday, November 27, 2007 4:03 AM
geetha
Hi,

I am using the BizTalk WCF Publishing wizard, and publishing Schema as web service. In the generated files, the code behind of .SVC file is not present. Is there any way to get the code behind file?

Thanks
Wednesday, January 23, 2008 11:14 AM
Anonymous
Anonymous
Hi Saravana,
I have develop one application in BIZTalk 2006 and was working fine.
Recently I have updated BizTalk with R2, I application is depolyed without any error.
But whenever I make a request it gives me the following error.

System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: services-internal.kystverket.no/.../...rOperation.
at System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest()
at System.Web.Services.Protocols.SoapServerProtocol.RouteRequest(SoapServerMessage message)
at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)

Can you help me?
Thanks in Advance
Eknath
Friday, February 15, 2008 7:47 AM
Anonymous
Anonymous
Hi.

Im new in biztalk.

When building exactly the same thing on Web Port Types (not soap types) i get:

The published message could not be routed because no subscribers were found. This error occurs if the subscribing orchestration or send port has not been enlisted, or if some of the message properties necessary for subscription evaluation have not been promoted. Please use the Biztalk Administration console to troubleshoot this failure.

Is it because schema used for SOAP message is not good atall for xxx_request?

It works perfectly when start port in Orchestration is not "Web Message Type" (but custom schema for example) and i construct the Web Message (Message_1_LoginRequest) manually a'la
Message_1_LoginRequest.username = xpath(StartMessage,...)
Message_1_LoginRequest.password = xpath(StartMessage,...)


Doing same thing with SOAP messages - i get only property "parameters" there to manipulate, but i need to sign sessionID somehow for next message sent to service.

Thnx for responce.
Monday, March 03, 2008 10:04 PM
Praveen
Praveen
I have an orchestration working for a file share, now I want to publish the same functionality as WCF web service.[Input a request like employee number, response is like emplyee details]

I have published using a WCF web service wizard. created the 2 files(.cs and config). Is this a correct approach to the solution. When I try to use a winform app to test. I cant get a response.
Tuesday, May 13, 2008 4:24 PM
yogesh
Hi sarvana,
I dont want to drop the xml as a input message. I want a call a method written in one of asmx web service which i added using method given by you in this post. Also i want some return values from BizTalk server to method which i want to pass to UI application which is calling my web service. How to go for this scenario.

Thanks in advance
Friday, June 20, 2008 6:38 PM
Anonymous
Anonymous
Thanks!

How can i update the WCF reference once i have already added in my project, there is no option so called "Updated WCF Service". Am i required to delete the existing files and add reference again.

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading