Call a webservice with an “object” parameter from orchestration

Home Page Forums BizTalk 2004 – BizTalk 2010 Call a webservice with an “object” parameter from orchestration

Viewing 1 reply thread
  • Author
    Posts
    • #20494

       Hi,

      I am working on a project where I need to call a remote WS from an orchestration.

       

      I started out by adding a web reference to my orchestration but received the error “Failed to add Web Refernece”. I did some research about this issue but didn’t find a solution to the problem.

       

      I then took another route by manually creating the proxy class via the wsdl.exe tool which in short gave me the following method signature:

       

      public object Foo(ref string vReturn, object vXML)

      {

      object[] results = this.Invoke(“Method”, new object[] {

                          (object)vReturn,

                           vXML});

                  vReturn = results[1].ToString();

                  return ((object)(results[0]));

        }

      }

       

      Next I created a custom pipeline component to construct the multipart message required for the Web Service call 

       

      // private component method

      IBaseMessage CreateMessage(Stream s, IBaseMessageFactory msgFactory, IBaseMessageContext context)

      {

           IBaseMessage msg = msgFactory.CreateMessage();

       

           IBaseMessagePart part = msgFactory.CreateMessagePart();

           part.Data = s;

       

            msg.Context = context;

       

            //vReturn

            IBaseMessagePart vReturn = msgFactory.CreateMessagePart();

            byte[] firstPart =  

      System.Text.Encoding.UTF8.GetBytes(string.Format(“<string>{0}</string>”, “”));

            vReturn.Data = new MemoryStream(firstPart);

            vReturn.Charset = “utf-8”;

            vReturn.ContentType = “text/xml”;

            msg.AddPart(“vReturn”, vReturn, false);

       

       

            //vXML

             msg.AddPart(“vXML”, part, true);

       

            return msg;

       }

       

       

      I then configured the solicit-response SOAP sendport to use the GACed proxy class.

       

      However I’m now getting the following error:

       

      “Error Description: Failed to serialize the message part “vXML” into the type “Object” using namespace “”. Please ensure that the message part stream is created properly.”

       

      Any help to take me further is appreciated!

       

      Regards,

       

      //Ershad

    • #20495

      Since you are on R2, I would recommend using the WCF-BasicHttp adapter instead of the SOAP adapter.  This adapter has a schema generation wizard which works much better than adding a web reference.  Here is a walkthrough  http://msdn.microsoft.com/en-us/library/bb246019.aspx.  Also, the WCF adapters will greatly improve your life over the SOAP adapter 🙂

      • #20505

         

        Thanks Russell for a great response! I’ll try it out and return with an update!

         

        //Ershad  

      • #20519

         Hi Russell,

        I got the add web reference to work with the WCF schema generation wizard. The schema generated for the web service request looks as followed:

         

        <xs:schema .  .   .>

          <xs:element name=ImportJobPC_XML>

            <xs:complexType>

              <xs:sequence>

                <xs:element minOccurs=0 maxOccurs=1 name=vReturn />

                <xs:element minOccurs=0 maxOccurs=1 name=vJobXML />

              </xs:sequence>

            </xs:complexType>

          </xs:element>

        </xs:schema>

         

        I need to set the vRetur element and vJobXML in my orchestration and pass it to the web service. Currently this is implemented with VB6 code calling the web service. In the VB6 code the vReturn parameter is set to a string value and the vJobXml is an xml passed as string.   

         

        I want to achieve the same thing in BizTalk.

         

        What I get into BizTalk is an XML-document which corresponds to the vJobXML and the vReturn element is just a constant string.  

         

        I’ve tried to create a map in my orchestration but mapping over element of type string to an anyType element doesn’t seem to work.

         

        I appreciate any suggestions?

         

        Regards,

         

        //Ershad

      • #20520

         Hi again,

        The webservice is public with url: http://129.35.74.93/MPNetWS/ImportWS.wsdl

         //Ershad

        • #20522

          Hi Ershad,

          You have a couple of options:

          1.  In the map, use a Mass Copy functoid to copy the any  node into another XML document.

          2.  Use the xpath() function to pull out the XML you want.  Example:

          jobXmlMessage = xpath(wsResponse, “/*[local-name()=’ImportJobPC_XML’]/*[local-name()=’vJobXML’]”);

          That would need to go in a message asignment shape.

          3.  Configure the WCF adapter to auto extract this XML for you.  On the Messages tab of the adapter config, you can enter an XPath expression to run on the web service response.  You could just put in the XPath above, and then in your orchestration you would receive just the vJobXML.  Cool huh?

          I don’t know if that XPath is right, so you will need to test.  Here is the best XPath testing tool I have found:  http://www.biztalkgurus.com/blogs/biztalksyn/archive/2007/11/25/dansharp-xmlviewer.aspx

          Let me know how it goes!

          • #20523

             Hi Russell,

            Options 1 and 2 are definately interesting. But I don’t think option 3 is. The message that comes in to the orchestration comes in via the FILE adapter.

            I’m not sure if i’ve picked the best solution for this problem but what I’m doing is that I recunstruct the message in a receive pipeline to a multiprt message just as described in my first post. I then need to map this recontructed message to the web service request in my orchestration.

            I’m now trying to call a orchestration facade (external .NET assembly) to pull the body parts out form the incoming message and map them to the web service request message.

            Sure thing i’ll return with an update:-)

            Thanks a lot for your posts!!!

            //Ershad 

            • #20524

              Oh, for the options I posted, I was talking about extracting XML from the web service response received via the WCF adapter.  Option 3 is a useful technique for getting web service responses, but not possible when receiving data from a file adapter.  However, options 1 & 2 are applicable with the file adapter.

              • #20540

                 

                I spoke with a former colleague of mine about this issue yesterday. He mentioned that if the “add reference” in a BizTalk project fails that should give a warning signal.  I explained to him how I used wsdl.exe tool to generate a proxy and that the proxy expects an “object” as parameters when invoking the web service. He quickly responded that the problem is that BizTalk can’t just serialize the “object” as the type is unknown. With that said this practically leaves me with the options to convince the exposer of the web service to rewrite the interface to “typed method signature” or rewrite the service.

                //Ershad

Viewing 1 reply thread
  • The forum ‘BizTalk 2004 – BizTalk 2010’ is closed to new topics and replies.