none
Adding C# Soap Header to a client that calls BT2010 Orchestration published as a WCF Web Service RRS feed

  • Question

  • I've added code from this reference to my orchestration (that is published as a WCF webservice):
    Accessing SOAP Headers in Orchestrations.

    I have a C# client that I was previously using before I was using any of the SOAP Headers.  I've been looking at dozens of blogs, and find the answers to anything related to SOAP Headers most confusing (and often specific to unique cases). 

    I'm using BT2010.  How can I add username, password, and a custom header called "ApplicationID" to my existing C# program and pass it to the orchestration/web service?

    Thanks,

    Neal

    Monday, February 16, 2015 9:24 PM

Answers

  • As long as I don't need a customer header (like the ApplicationID), this is all I needed:

    MyClient client = new MyClient();  // wcf service reference
    
    client.ClientCredentials.UserName.UserName = "testuser";
    client.ClientCredentials.UserName.Password = "testpass"; 


    and added this to my app.config in the   <security mode="Transport"> section:

    <transport clientCredentialType="Basic" proxyCredentialType="None" realm="" />
    Neal



    • Marked as answer by Neal Walters Tuesday, February 24, 2015 3:32 PM
    • Edited by Neal Walters Tuesday, February 24, 2015 3:33 PM
    Friday, February 20, 2015 5:07 PM

All replies

  • Besides what you mentioned above, you can also refer this document to use SOAP header, see: https://msdn.microsoft.com/en-us/library/bb245946.aspx

    Hope it helps.

    Tuesday, February 17, 2015 8:20 AM
  • Thanks, but that link is applicable I believe only to consuming someone else's webservice in an orchestration.  I'm publishing an orchestration to a customer who calls me.

    Also, I'm asking how to add the SOAP Headers to my C# console client tester program, not to BizTalk.

    I'm attempting this in the orchestration, but don't know how to pass the values:

    vInboundHeaders = "user=" + msgIncoming(SOAP.Username) +
                      " password=" + msgIncoming(SOAP.Password) +
                      " unknown=" + msgIncoming(SOAP.UnknownHeaders);

    In the C# client I've started with this: 

        public class CustomSoapHeader : SoapHeader
        {
            [System.Xml.Serialization.SoapElement("USER")]
            [System.Xml.Serialization.SoapAttribute("USER")]
            public string Username;
            [System.Xml.Serialization.SoapAttribute("PASSWORD")]
            public string Password;
            public string ApplicationID;
        }

    and later:

                soapHeader1.Username = "test1";
                soapHeader1.Password = "test12345";
                soapHeader1.ApplicationID = "muappid";

    But not sure that is right, then not sure how to attach those headers to the client call.

    Neal


    • Edited by Neal Walters Tuesday, February 17, 2015 10:46 PM
    Tuesday, February 17, 2015 10:41 PM
  • Hi Neal,

    You can refer to Publishing Web Services with SOAP Headers. You can add SOAP headers to your Web services when you run the BizTalk Web Services Publishing Wizard. 

    How to achieve this? Refer: Using the BizTalk Web Services Publishing Wizard to Publish an Orchestration as a Web Service


    Please mark as answer or vote as helpful if my reply does



    Wednesday, February 18, 2015 2:38 AM
    Moderator
  • Rachit,

    The "BizTalk Web Services Publishing Wizard." is for .asmx web services, I'm using "BizTalk WCF Publishing Wizard", a big difference!

    Neal


    • Edited by Neal Walters Wednesday, February 18, 2015 4:09 PM
    Wednesday, February 18, 2015 4:08 PM
  • Neal,

    The BizTalk WCF Service Publishing Wizard does not include custom SOAP header definitions in the generated metadata. To publish metadata for WCF services using custom SOAP headers, you should manually create a Web Services Description Language (WSDL) file. You can use the externalMetadataLocation attribute of the <serviceMetadata> element in the Web.config file that the wizard generates to specify the location of the WSDL file. The WSDL file is returned to the user in response to WSDL and metadata exchange (MEX) requests instead of the auto-generated WSDL.

    The following XML data shows an example of a part of the WSDL file defining custom SOAP headers:

    <wsdl:operation name="Request">
      <soap12:operation soapAction="http://Microsoft.Samples.BizTalk.NetTcpAdapter/OrderProcess/IOrderProcess/Request" style="document" /> 
       <wsdl:input name="Order">
         <soap12:header message="i0:Order_Headers" part="SalesAgent" use="literal" /> 
         <soap12:body use="literal" /> 
       </wsdl:input>
       <wsdl:output name="OrderConfirmation">
         <soap12:header message="i0:OrderConfirmation_Headers" part="PaymentAgent" use="literal" /> 
         <soap12:body use="literal" /> 
       </wsdl:output>
    </wsdl:operation>
    
    

    Refer: SOAP Headers with Published WCF Services

    Rachit


    Please mark as answer or vote as helpful if my reply does

    Wednesday, February 18, 2015 4:22 PM
    Moderator
  • As long as I don't need a customer header (like the ApplicationID), this is all I needed:

    MyClient client = new MyClient();  // wcf service reference
    
    client.ClientCredentials.UserName.UserName = "testuser";
    client.ClientCredentials.UserName.Password = "testpass"; 


    and added this to my app.config in the   <security mode="Transport"> section:

    <transport clientCredentialType="Basic" proxyCredentialType="None" realm="" />
    Neal



    • Marked as answer by Neal Walters Tuesday, February 24, 2015 3:32 PM
    • Edited by Neal Walters Tuesday, February 24, 2015 3:33 PM
    Friday, February 20, 2015 5:07 PM