Custom Soap Header

Home Page Forums BizTalk 2004 – BizTalk 2010 Custom Soap Header

Viewing 2 reply threads
  • Author
    Posts
    • #20783

      I have a custom header in my webservice. I want to access this custom header in my Biztalk. How can I do that?

    • #20784

       Is this a WCF service?  If not, consuming SOAP headers in ASMX (or basic SOAP services) is explained a bit here … http://msdn.microsoft.com/en-us/library/ms946937.aspx

      It’s not as clean with the WCF adapters (http://msdn.microsoft.com/en-us/library/bb246026.aspx)

      • #20785

         I am not using WCF Service. Its an asmx. I think you are pointing me in the right direction but I didn’t really understand it. The link shows a wsdl file, but not how to access the soap header defined in my asmx. Or am I missing something?

      • #20786

        I would go the WCF adapter route regardless of whether the service platform is WCF.  The WCF adapters totally rock.  If the service is built on WCF, use the WCF-WSHttp adapter (or the WCF-NetTcp adapter for faster performance if everything is behind the firewall).  If the service is basic SOAP, use the WCF-BasicHttp adapter.

        • #20787

          Here is a walkthrough on consuming a service with the WCF-BasicHttp adapter:

          http://msdn.microsoft.com/en-us/library/bb246019.aspx

          To send custom SOAP headers to the service, you just need to set the value of the WCF.OutboundSoapHeaders context property.  See the WCF link that Richard posted above for more info on how to do that.

          • #20788

             So do I have change my .asmx to WCF Service to get the header thing work?

            What I want to achieve is ..I want to encapsulate the custom header that I have created in my web service and the return of my webmethod as content into a soapenvelope and then send this soapenvelope back.

            I do not wnat to create a custom header inside Biztalk, I want to consume already defined custom header of my webservice inside Biztalk

             

            • #20789

              No, you don’t have to change your ASMX service to WCF to get this to work.  I would, however, recommend using the WCF-BasicHttp adapter to access the ASMX service and headers.  The adapter is built on WCF, but it can actually talk to any kind of service that speaks SOAP (including ASMX).  Plus the WCF adapters are way easier to use than the SOAP adapter.

              So let’s assume that you defined a SOAP header on your service and named it MyHeader.  Now, you want to set the value of that service when you consume the service from BizTalk.  To do so, you would just set the value of the WCF.OutboundCustomHeaders context property on your outgoing message to the service.  For example, you would need to put this code in a message assignment shape:

              OutboundMessage(WCF.OutboundCustomHeaders) = “<MyHeader>Foo</MyHeader>”;

              The WCF adapter will automatically see the context property and jam the headers into the outbound SOAP envelope.

              • #20795

                 I am trying to use the WCF adapter. So I am changing my orchestration now.
                I have to send certain input parmeters to the webmethod. How can I do that using WCF.
                I tried WCFRequest.parameters.. does let me add stuff.

                • #20803

                  You need to generate a schema to send to the web service. The schema will contain all of the parameters, so you just need to declare a message of that type and fill in the parameters. Then send the message to the service. Check out the walkthrough link I posted above. It has more details.

                  • #20805

                    Hi Russell,

                    Thanks for the reply. I tried to follow the msdn link that you provided but ran into problems while choosing the MEX endpoint in the consume WCF Service wizard so I am not able to go forward with this sample. Error as below.

                    A name was started with an invalid character. Error processing resource ‘http://localhost/BasicHttpWcfServiceConsuming/Orde&#8230;

                    So, I am trying with my project now. I added my .asmx using the WCF Consume Service wizard. It generated _tempyuri_org.xsd file which contains the request and response fot the webmethod.

                    so, I created message_1 of type request.. so far good.

                    Now, in my Message Assignment, I tried Message_1. .. nothing come up.. hoping to set parameters here.. What should I do now..

                     

                    • #20806

                      Check out this thread for some options for initializing a message in BizTalk:  http://www.biztalkgurus.com/forums/t/10556.aspx.

                      • #20807

                         I have checked out the link that you sent me. In all of the four options that you suggested, I am not sure how any of them would work for me.

                        You suggested this code.. msgOut.MsgPart1 = xmlDocMessage; in one of your responses.

                        But when I do that .(dot) nothing come up for me.

                        Any other way to send parameter values to Webmethod?

                      • #20808

                        You don’t need the dot.  Your code would probably look like this:

                         

                        msgOut = xmlDocMessage;

                         

                        You only need a dot if you are sending a mulitpart message. The message you are sending to the service is a single XML file, so you don’t need a dot.

                      • #20809

                         So, If I understood correctly, I should have some schema for the Request.

                        In my case, I don’t have a seperate schema for the request. I get a whole Soapmessage as a XML document and I am doing Xpath queries(as discussed in our old posts) to retieve some values and then send them to the webmethod.

                        The schema that _tempuri produces is diffrent from what I get from the XMLDocument

                      • #20812

                        No, you don’t need a schema for the request (if you were using the mapping method you would, but it sounds like you’re using the XmlDocument method).  

                        For example, assume your web service takes 2 parameters named param1 and param2.  You would create two string variables in orchestration view and call them strParam1 and strParam2.  Then you would assign to them using xpath().  Then you would build them into the XML string you are loading.  Your code would look something like this:

                        strParam1 = xpath(Request, “//*[local-name()=’param1′]”);

                        strParam2 = xpath(Request, “//*[local-name()=’param2′]”);

                        WebRequestXml = new System.Xml.XmlDocument();

                        WebRequestXml.LoadXml(“<WebMethodName xmlns=’http://www.tempuri.org’><param1>&#8221; + strParam1 + “</param1><param2>” + strParam2 + “</param2></WebMethodName>”);

                        To get the web request XML format right, you should generate an instance of the _tempuri schema.  Use the generated schema as a template for the XML string that you load in the LoadXml method.

                         

              • #22630

                When using WCF.OutboundCustomHeaders, it must have the <headers> element as the root element. If the custom SOAP is empty, you must assign  <headers></headers>

                Example

                MyMessage(WCF.OutboundCustomHeaders) = “<headers><T1> xx</T1></headers”

                OR

                MyMessage(WCF.OutboundCustomHeaders) = “<headers></headers”

                 

    • #22634

      While it makes life easier, you do not need wcf…

      If your orchestration is exposed as a web service:

      Edit the asmx project that is created.  Here you will see the guts of how to add a message to biztalk using a function call!  You will also have full access the the iis http data (your soap headers).  You can then add this data either to the message body before calling the “add to biztalk” function, or I think there is a message header portion of the “add to biztalk” function.

      If your orchestration sending to a web service:

      You can implement a custom proxy rather than using a web reference.  Using wsdl.exe will give you the proxy code.  You can then intercept the return from the proxy call before it is written to biztalk and in doing so again access all that goodness.

       

       

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