Consuming Web Services without web reference in BizTalk


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. 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 the 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. “.

 

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 of the web service (which was most likely too) then I had 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 xsd’s).

 

 web_reference

 

 

BizTalk will then use 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.xsd’s generated.

 

The trick is if we can generate these items for BizTalk we can surely call the web service without using web reference. The work around for this is generating the proxy class from wsdl.exe. You can generate the proxy class from 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/%5Bwebservice 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 web port (which come from the web reference). We can supply the AsemblyName and MethodName from the proxy class we created. After its 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.


technorati tags :
Advertisements

15 Responses to Consuming Web Services without web reference in BizTalk

  1. mercedes says:

    Hi Rafay,

    We are trying with a proxy class but we are retrieving an error in the service response… The problem is the message that we send to the destination is sent empty… The proxy class may be sending this in a wrong way… but why???

    Could you help us?

    Thanks in advance.

    Regards,
    Mercedes

  2. mani says:

    Hi Abdul,

    At present we are using Biztalk server in our application. When i set the receive location and the send port as FILE (Transport Prop) then my application is working fine, and i am getting all the records in the database as an XML file format.

    now i changed the receive port as a “request-response” port, again i deploied my biztalk project, and i publised my orchestration as a webservice in IIS, using “BizTalk Web Services Publishing Wizard”.

    I added a new receive location as request-response port and set the transport porp as SOAP, and configured the biztalk application.

    i added the published biztalk_Proxy in my IIS as web reference to my .net application. i’m getting the result but it is showing only one record (the top most record) of the database. not showing all the records as it showed in the XML file..

    So please help me to get the total records from the database to my application…..

    thanks in advance…….

    • Abdul Rafay says:

      You have to set the MaxOccurs property of the repeating record node to “unbounded” in the response schema. Update the schema and redeploy the project. Publish the web service again through the wizard. Then update the web reference in your calling application. This will create an array of the record that is repeating (has multiple records) in the .NET code. You can then enumerate this record to get the results.

  3. mani says:

    Thank you Abdul,
    Your solution helped me a lot.
    i exactly got the result, that what i expected.

    Thank you very much ….

  4. mani says:

    Hi abdul…
    here i have one more problem with xml prepareation…

    My Output xml should be like this…


    Abdominal Pain
    1
    XYZ

    1234
    2345


    Abdominal Pain
    2
    XYZ

    1234
    2345


    Abdominal Pain
    3
    XYZ

    1234
    2345

    I got the exact result in my plain xml format..

    But when i published my biztalk application as a web service ..then the resultant xml is as follows….


    Abdominal Pain
    1
    XYZ


    Abdominal Pain
    2
    XYZ


    Abdominal Pain
    3
    XYZ

    Here i`m loosing the hierarchy… at the node …

    i tried with so many properities as you said in my previous problem… But i did not get the result… Please help me on this issue…

    Thanks in advance….

  5. mani says:

    Sorry Abdul Tags were missed…
    So i`m sending my format again… Please don’t mind…

    “(” as “”

    here i have one more problem with xml prepareation…

    My Output xml should be like this…

    (AAAAA xmlns:xsi=”********” xmlns:xsd=”http://*********”)
    – (BBBBBBB)
    —–(cccc)Abdominal Pain(/cccc)
    —–(dddd)1(/dddd)
    —–(EEEE)XYZ(/EEEE)
    —–(FFFF)
    ———-(GGGG)1234(/GGGG)
    ———-(GGGG)2345(/GGGG)
    —–(/FFFF)
    (/BBBBBBB)
    – (BBBBBBB)
    —–(cccc)Abdominal Pain(/cccc)
    —–(dddd)2(/dddd)
    —–(EEEE)XYZ(/EEEE)
    —–(FFFF)
    ———-(GGGG)1234(/GGGG)
    ———-(GGGG)2345(/GGGG)
    —–(/FFFF)
    (/BBBBBBB)
    – (BBBBBBB)
    —–(cccc)Abdominal Pain(/cccc)
    —–(dddd)3(/dddd)
    —–(EEEE)XYZ(/EEEE)
    —–(FFFF)
    ———-(GGGG)1234(/GGGG)
    ———-(GGGG)2345(/GGGG)
    —–(/FFFF)
    (/BBBBBBB)
    (/AAAAA)

    I got the exact result in my plain xml format..

    But when i published my biztalk application as a web service ..then the resultant xml is as follows….

    (AAAAA xmlns:xsi=”********” xmlns:xsd=”http://*********”)
    – (BBBBBBB)
    —–(cccc)Abdominal Pain(/cccc)
    —–(dddd)1(/dddd)
    —–(EEEE)XYZ(/EEEE)
    —–(FFFF /)
    (/BBBBBBB)
    – (BBBBBBB)
    —–(cccc)Abdominal Pain(/cccc)
    —–(dddd)2(/dddd)
    —–(EEEE)XYZ(/EEEE)
    —–(FFFF /)
    (/BBBBBBB)
    – (BBBBBBB)
    —–(cccc)Abdominal Pain(/cccc)
    —–(dddd)3(/dddd)
    —–(EEEE)XYZ(/EEEE)
    —–(FFFF /)
    (/BBBBBBB)
    (/AAAAA)

    Here i`m loosing the hierarchy… at the node (FFFF)…

    i tried with so many properities as you said in my previous problem… But i did not get the result… Please help me on this issue…

    Thanks in advance….

    • mani says:

      got the solution Abdul…

      due to in valid data type it is not showing the result..

      I changed the data type .. and then i got the out put…

      Sorry to disturb you…
      Any how thanks once again….

      Mani…

  6. manikanta says:

    hi abdul…
    I need one more help form you…
    actually i`m getting data from database, and and the data is binding like the followin way…. When i set to the max occurence prop to unbound.

    “(AAAA ABC=“XYZ” SDF=“FGHFGHFGH” FGHH=“SDFSDF”)”
    ” (BBB=“123123123” NNN=““ /) ”
    ” (BBB=“123123123” NNN=““ /) ”
    ” (BBB=“123123123” NNN=““ /) ”
    ” (BBB=“123123123” NNN=““ /) ”
    ” (BBB=“123123123” NNN=““ /) ”
    ” (CCC=“234234” DDD=“lkjlkj” /) ”
    ” (CCC=“123123” DDD=“sdfsdf” /) ”
    ” (CCC=“345345” DDD=“werwer” /) ”
    ” (CCC=“456456” DDD=“sdffgh” /) ”
    ” (CCC=“135135” DDD=“poiwer /) ”
    ” (EEE /) ”
    ” (EEE /) ”
    ” (EEE /) ”
    ” (EEE /) ”
    ” (EEE /) ”
    ” (FFF)AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA(/FFF) ”
    ” (FFF)AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA(/FFF) ”
    ” (FFF)AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA(/FFF) ”
    ” (FFF)AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA(/FFF) ”
    ” (FFF)AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA(/FFF) ”
    ” (GGG)BBBBBBBBBBBBBBBBBB(/GGG) ”
    ” (GGG)BBBBBBBBBBBBBBBBBB(/GGG) ”
    ” (GGG)BBBBBBBBBBBBBBBBBB(/GGG) ”
    ” (GGG)BBBBBBBBBBBBBBBBBB(/GGG) ”
    ” (GGG)BBBBBBBBBBBBBBBBBB(/GGG) ”
    ” (/AAAA)“

    if i do not set the max occurence prop to unbound my xml document is like the following..

    “(AAAA ABC=“XYZ” SDF=“FGHFGHFGH” FGHH=“SDFSDF”)”
    (BBB=“123123123” NNN=““ /) ”
    (CCC=“234234” DDD=“lkjlkj” /) ”
    (EEE /) ”
    (FFF)AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA(/FFF) ”
    (GGG)BBBBBBBBBBBBBBBBBB(/GGG) ”
    ” (/AAAA)“

    “(AAAA ABC=“XYZ” SDF=“FGHFGHFGH” FGHH=“SDFSDF”)”
    (BBB=“123123123” NNN=““ /) ”
    (CCC=“123123” DDD=“sdfsdf” /) ”
    (EEE /) ”
    (FFF)AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA(/FFF) ”
    (GGG)BBBBBBBBBBBBBBBBBB(/GGG) ” ”
    (/AAAA)“

    “(AAAA ABC=“XYZ” SDF=“FGHFGHFGH” FGHH=“SDFSDF”)”
    (BBB=“123123123” NNN=““ /) ”
    (CCC=“345345” DDD=“werwer” /) ”
    (EEE /) ”
    (FFF)AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA(/FFF) ”
    (GGG)BBBBBBBBBBBBBBBBBB(/GGG) ” ”
    (/AAAA)“

    “(AAAA ABC=“XYZ” SDF=“FGHFGHFGH” FGHH=“SDFSDF”)”
    (BBB=“123123123” NNN=““ /) ”
    (CCC=“456456” DDD=“sdffgh” /) ”
    (EEE /) ”
    (FFF)AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA(/FFF) ”
    (GGG)BBBBBBBBBBBBBBBBBB(/GGG) ” ”
    (/AAAA)“

    “(AAAA ABC=“XYZ” SDF=“FGHFGHFGH” FGHH=“SDFSDF”)”
    (BBB=“123123123” NNN=““ /) ”
    (CCC=“135135” DDD=“poiwer /) ”
    (EEE /) ”
    (FFF)AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA(/FFF) ”
    (GGG)BBBBBBBBBBBBBBBBBB(/GGG) ” ”
    (/AAAA)“

    and i need the actual output like this…

    “(AAAA ABC=“XYZ” SDF=“FGHFGHFGH” FGHH=“SDFSDF”)”
    (BBB=“123123123” NNN=““ /) ”
    (CCC=“234234” DDD=“lkjlkj” /) ”
    (CCC=“123123” DDD=“sdfsdf” /) ”
    (CCC=“345345” DDD=“werwer” /) ”
    (CCC=“456456” DDD=“sdffgh” /) ”
    (CCC=“135135” DDD=“poiwer /) ”
    (EEE /) ”
    (FFF)AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA(/FFF) ”
    (GGG)BBBBBBBBBBBBBBBBBB(/GGG) ”
    ” (/AAAA)“

    is there any possibility to get such output in biztalk…????

    thanks in advance…
    MANI…

  7. Sivagurunathan says:

    Hi,

    I need to develop an orchestration which should consume the webservice and send the xml data to that webservice

  8. trofnais says:

    Hi Abdul,

    With BizTalk I tried to connect to SQL Reporting Services (SQL 2008) integrated to Sharepoint (MOSS 2007) by calling the web services http://server//_vti_bin/ReportServer/ReportService2006.asmx and http://server//_vti_bin/ReportServer/ReportExecution2005.asmx
    I constructed my orchestration and send ports to call the method ‘GetReportParameters’ of ReportService2006.asmx web service. In my orchestration I added web Reference and I tested my orchestration and got the error ‘ “Failed to load “” type ….’ . I did what you suggested in your post and I have the error ‘The parameter value provided for ‘snapshotID’ does not match the parameter type’.

    I tried with WCF Send Port (basicHttp, Custom… with Basic, Digest, NTLM and Windwos credentials) and I got an authentication error (I have the full right on Sharepoint server and reporting services server) : (401) Unauthorized

    Please help me on this issue…

    Thanks in advance….

  9. zoli says:

    Any code to download? Please man..

  10. VKS says:

    Got a question here, and would appreciate any help with this!!!

    In BizTalk 2009, I have a dynamic send port whose address is configurable, and read from the BTSNTSvc64.exe and BTSNTSvc.exe config files. Say, this address is http://xyz.com/.

    And to create request-response messages for this service, I consume the same WCF service in the BizTalk project, which creates all its related .odx, .xsd, and bindinginfo.xml files. In the bindinginfo.xml files, I see a hard-coded reference to this service URL “http://xyz.com” (which is expected). After deployment, everything works fine till this point.

    Now, if I want to deploy this onto another server, where I want the dynamic send port to go against a different WCF service (which is configured in the local server’s BTSNTSvc64.exe and BTSNTSvc.exe config files), it still goes to the one defined in the bindinginfo.xml files (http://xyz.com/). Across the servers, both the WCF services have the same schema, signature and definition – only the URLs are different.

    And unfortunately, I cannot import bindinginfo.xml files across different BizTalk server deployments, and edit them with respective URLs.

    My question is if it’s a dynamic send port, whose address is configurable, why it still goes against the one I have in the bindinginfo.xml file?

    Thanks for your help in advance. Let me know if you need more details.

    – VKS.

  11. Radhakrishna Teegala says:

    Hi abdul,

    Following is orchestration design. Multipart message are not appearing in BizTalk map-per, because those are simple types (Primitive types (String)) or .Net types.
    So I’m constructing the output message using message assignment shape in orchestration.

    Following is message construction.
    “TempString =@”” + WebOut.assetinvitemcode + “” + WebOut.assetserialid+””+WebOut.nin+””+WebOut.officeid+””+WebOut.assetdescription+””+WebOut.assetinvitemcode+””+ WebOut.feederid +””;
    TempXML.LoadXml(TempString);
    Out = TempXML; “
    But I’m getting the XLANGS exception. You can find exception end of mail.

    But I can find the response message from the service in the suspend message. But it giving multipart message with simple types.

    Exception:

    xlang/s engine event log entry: Uncaught exception (see the ‘inner exception’ below) has suspended an instance of service ‘AssetDetails.Assets(49372eac-dd46-aa86-6ea9-e876cbd58016)’.
    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: 6201f98f-e5ae-47f7-9ea3-fcb4321d25f0
    Shape name: ConstructMessage_Out
    ShapeId: 379b0f21-ede7-4b08-ae72-1d14e0b06fdf
    Exception thrown from: segment 2, progress 17
    Inner exception: There is an error in XML document (0, 0).

    Exception type: InvalidOperationException
    Source: System.Xml
    Target Site: System.Object Deserialize(System.Xml.XmlReader, System.String, System.Xml.Serialization.XmlDeserializationEvents)
    The following is a stack trace that identifies the location where the exception occured

    at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
    at System.Xml.Serialization.XmlSerializer.Deserialize(TextReader textReader)
    at Microsoft.XLANGs.Core.Value.GetObject(Type t)
    at Microsoft.XLANGs.Core.Value.RetrieveAs(Type t)
    at Microsoft.XLANGs.Core.Part.ProtectedRetrieveAs(Type t)
    at Microsoft.XLANGs.Core.Part.RetrieveAs(Type t)
    at AssetDetails.WebReference.getAssetDetailsServiceService_.__System_String__.get_TypedValue()
    at AssetDetails.Assets.segment2(StopConditions stopOn)
    at Microsoft.XLANGs.Core.SegmentScheduler.RunASegment(Segment s, StopConditions stopCond, Exception& exp)
    Additional error information:

    Root element is missing.

    Exception type: XmlException
    Source: System.Xml
    Target Site: Void Throw(System.Exception)
    The following is a stack trace that identifies the location where the exception occured

    at System.Xml.XmlTextReaderImpl.Throw(Exception e)
    at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
    at System.Xml.XmlTextReaderImpl.Read()
    at System.Xml.XmlTextReader.Read()
    at System.Xml.XmlReader.MoveToContent()
    at System.Xml.Serialization.XmlSerializationPrimitiveReader.Read_string()
    at System.Xml.Serialization.XmlSerializer.DeserializePrimitive(XmlReader xmlReader, XmlDeserializationEvents events)
    at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: