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(18) | 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.
Wednesday, December 03, 2008 8:30 PM
Sreeni us
Sreeni
Nice Article. I tried to change Port_1 to use "WcfSendPort_Service_ServiceSoap12" as opposed to "WcfSendPort_Service_ServiceSoap". I get the following error. Any idea?

Uncaught exception (see the 'inner exception' below) has suspended an instance of service 'ConsumeWebService.ServiceClient(aec68c72-e652-a27f-6e58-322ddaa9210c)'.
The service instance will remain suspended until administratively resumed or terminated.
If resumed the instance will continue from its last persisted state and may re-throw the same unexpected exception.
InstanceId: d6877a91-b997-47d7-8fea-7b7a243eba6e
Shape name: Receive_2
ShapeId: c630acf4-eb65-490f-be63-af1852b70d8d
Exception thrown from: segment 1, progress 10
Inner exception: Received unexpected message type 'http://www.w3.org/2003/05/soap-envelope#Fault' does not match expected type 'http://tempuri.org/#ConcatNameResponse'.

Exception type: UnexpectedMessageTypeException
Source: Microsoft.XLANGs.Engine
Target Site: Void VerifyMessage(Microsoft.XLANGs.Core.Envelope, System.String, Microsoft.XLANGs.Core.Context, Microsoft.XLANGs.Core.OperationInfo)
The following is a stack trace that identifies the location where the except
Saturday, December 13, 2008 8:40 PM
Girish in
Girish
Hi
i have a WCF service which i consummed in my biztalk project...( i don't know anything about that wcf service becz it has been develop by other person) after this i have deployed my project and imported binding info.....then i have configured the send ports...like i have three endpoints...so in url part of the configuration i have given particular endpoints url....in action part i have removed the default code which come like "<BtsActionMapping xmlns:xsi......" and given url link /function name. then i have host the orchestrion and started the project.
can u please tell me my steps are right or not for the same? and how can i call the particular data contract? and how i test the process....for the error which is comming....i want to know is that error is form my biztalk process or from WCF service side....please help in this.....my whole work is stopped becz of this...please help me and reply me on girish.fuluskar@gmail.com as soon as possible.....

thanks
Girish




Saturday, December 13, 2008 8:46 PM
Girish in
Girish
hi...

can u please tell me step by step process to consume and test the wcf process in biztalk 2006 r2....so that i can test my process...please help me on this....it very urgent.......

Girish
Wednesday, December 17, 2008 1:33 AM
Girish in
Girish
Hi.....i solved my WCF problem...and find the exact steps to do that......
Wednesday, December 17, 2008 7:43 AM
Girish in
Girish
hi.....
can anyone please tell me how i can retreive the message from WCF service.......i m trying to use the same steps whic i used to send the message to WCF service but here i m using WCF service as reciver but after deploy and importing binding info i m not getting any receive port and in orchestration binding not seen any receive service endpoint. Is i m following the right steps or is there any other way for it.....

please reply as soon as possible.

Girish

Friday, December 19, 2008 2:12 AM
Girish in
Girish
Hi

I have solved my WCF service issue realted to passing the value....now i want to receive the response from WCF service after send the request......i m sending the request through the request message multi part generated by service...but at the response side i m geting the response in list......i m not sure that biztalk will accept this thing becz at the response side i m using response message multi part generated by service......i m using the expression shape for timebeing after each step in orchestration to check the stage where i m getting the error.

The request is going to WCF service but response time it gives the error. I m using the following steps in orchestration.

** For request i have manually created the schema same as the request format of the datacontract

Receive Shape 1 --> Source Schema Message (** Manually created by me same as request format of the data contract)

Transform Shape --> Transform the Request into service endpoint function (Source Schema to data contract schema)

Send Shape --> Request Message (Multi-Part Message Type Generated by service for that data contract) ..this shape is attached to the request port in orchestartion which i have generated by using existing port type for that particular service endpoint

Receive Shape 2 --> Response Message (Multi-Part Message Type Generated by service for that data contract).... through this receive shape i m receiving the response..

it give me error as:

Inner exception: Received unexpected message type 'http://.....' does not match expected type
'http://......'.

I m not getting that is there any problem in my request format (which i have created manually).....or there is mismatch in response format becz i m geting the values in list...

Is i m following the right steps?
Please guide me on the same as soon as possible..

Thanks
Tuesday, December 23, 2008 10:53 AM
Girish in
Girish
Hi all biztalk pepole......
WCF is done...now it's time for MSMQ...my next challenge is due to file size i have breackup one message into 2 in MSMQ....now at the destination i want one output file which contain the 2 MSMQ message data....how can i do that....how biztalk will identify that particular message is divided into 2 mssages....

please send me the solution if any body have tryed on it..

Girish.

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading