Click here to Skip to main content
15,888,301 members
Articles / .NET

Consuming Web Services without web references in BizTalk

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
2 May 2009CPOL3 min read 36.2K   7   3
How to consume Web Services without web references in BizTalk.

Introduction

Last week, I came across a scenario where I had to call the card verification service before updating the credit/debit card status. This was the first time I was consuming a Web Service in an orchestration, so I had a little trouble in the beginning. Very innocently, I made request and response messages of the schema types which I got from the WSDL, made a request-response port, and deployed the project. I configured the port to use the SOAP adapter, and gave the URI of the Web Service. I tested my orchestration and was expecting the results, but got an exception in the system Event Log:

"Failed to load "" type.

Please verify the fully-qualified type name is valid. Details: "". 
The type must derive from System.Web.Services.Protocols.SoapHttpClientProtocol. 
The type must have the attribute System.Web.Services.WebServiceBindingAttribute".

The solution

After a little search on the Internet, I found out that I have to add the web reference of the Web Service and configure web ports and web messages, and cannot call the Web Service in this manner. However, I succeeded to consume the Web Service, but I had to consume the Web Service without adding the web references. Because, I figured out if the schemas change in the future (which was most likely too), then I would have to update the web references, recompile and redeploy the project.

Adding the web reference in my project, I got the following items which will be used by BizTalk to consume the Web Service:

  • Universal Resource locator (URI)
  • WSDL which contains the methods, ports, and message type information of the Web Service.
  • Reference map (which will contain XSDs).

web_reference

BizTalk will then use the web port types and web messages from the web reference generated items. It will capture web ports from the WSDL and web messages from the reference.xsds generated.

The trick is if we can generate these items for BizTalk, we can surely call the Web Service without using a web reference. The workaround for this is generating the proxy class from wsdl.exe. You can generate the proxy class from the Visual Studio command prompt, and giving the proper switches will create the proxy class.

You can see the MSDN help for more switches of WSDL.

wsdl /out:[dir]proxy.cs http://localhost/[webservice URI].asmx?wsdl

After generating the proxy class, you can add the proxy class to a .NET Library project, give it a strong name key file, build the project. (Don’t forget to GAC the generated assembly before deploying the BizTalk project).

Technically, the SOAP.MethodName and SOAP.AssemblyName properties are promoted to the context of the message before being published to the message box, and these values are supplied automatically when we use a web port (which come from the web reference). We can supply the AssemblyName and MethodName from the proxy class we created. After it is GAC’d, we can configure the send port of the orchestration and supply the AssemblyName and MethodName properties for the message context. After the BizTalk Project is deployed, we can configure the send port calling the Web Service. In the Web Service tab, select the assembly which was created before by building the .NET library project containing the proxy class. Select the type name and method name, and in the General tab, specify the Web Service URI.

proxy_port

In this way, you can have more control over the proxy and handle its versioning, and a little change in the Web Service won't make you build deploy the project again.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
Qatar Qatar
I am a BizTalk Server MVP for 2010 and an active blogger and a participant on the MSDN BizTalk Server Forums. I am currently working as a BizTalk Architect at a Bank in Qatar. Before this position I worked as a Sharepoint Consultant in UAE , BizTalk Architect in Bank Saudi Fransi in Saudi Arabia and United Bank Ltd in Pakistan.

I also achieved MCTS certification in BizTalk Application development in June 2008.

Click here to check out my Blog.

SQL Server Query Notification with BizTalk Server 2009 WCF SQL Adapter.

Envelope Wrapper.

Aggregator (Sequential Convoy)

Splitter (Debatching multiple records)
Resequencer
Recipient List
Scatter and Gather using Self Correlating Port

Comments and Discussions

 
QuestionHow to create request and response messages from the proxy? Pin
karan_23_j12-Oct-09 3:04
karan_23_j12-Oct-09 3:04 
AnswerRe: How to create request and response messages from the proxy? Pin
Abdul_Rafay12-Oct-09 4:40
Abdul_Rafay12-Oct-09 4:40 
GeneralRe: How to create request and response messages from the proxy? Pin
karan_23_j13-Oct-09 20:26
karan_23_j13-Oct-09 20:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.