How to add SOAP header to a SOAP message?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peter van der veen

    #1

    How to add SOAP header to a SOAP message?

    Hi

    I have the following problem.

    I'm calling a webservice from within a VB.net 2005 Windows program.
    For this i got a WSDL file and loaded that in VB.
    Until now i just call the webservice and everything works OK.

    Now i need to add an extra attribute/header element to the SOAP header
    before i contact the webservice.
    The webservice needs this to be in the SOAP header.

    Where and how do i do this? I have no clue at all.

    From the company that runs the webservice i got an example code in
    Java, but i have no idea where this had to be placed.


    Hope that soemone can help me or can direct me in a direction to find
    a solution

    JAVA Code:
    // Construct the header
    QName headerName = new QName(" http://ech.client.nl/vendor",
    "Vendor");
    SOAPHeaderEleme nt headerElement = new SOAPHeaderEleme nt(headerName);
    headerElement.s etValue("ECH Gui");
    headerElement.s etMustUnderstan d(true);

    try {
    Message message = arg0.getCurrent Message();
    message.getSOAP Header().addChi ldElement(heade rElement);
    } catch (SOAPException se) {
    logger.error("K an niet SOAP header 'Vendor' toevoegen", se);
    }

  • Peter van der veen

    #2
    Re: How to add SOAP header to a SOAP message?

    To be more precisely.

    The webservice i call is not a .NET webservice.
    In the WSDL are no header elements defined.

    To simplify the question.

    I call a webservice and i want to add an SOAP header (with a
    headerelement and a value) to the outgoing message.

    On Wed, 08 Nov 2006 10:18:22 +0100, Peter van der veen <wrote:
    >Hi
    >
    >I have the following problem.
    >
    >I'm calling a webservice from within a VB.net 2005 Windows program.
    >For this i got a WSDL file and loaded that in VB.
    >Until now i just call the webservice and everything works OK.
    >
    >Now i need to add an extra attribute/header element to the SOAP header
    >before i contact the webservice.
    >The webservice needs this to be in the SOAP header.
    >
    >Where and how do i do this? I have no clue at all.
    >
    >From the company that runs the webservice i got an example code in
    >Java, but i have no idea where this had to be placed.
    >
    >
    >Hope that soemone can help me or can direct me in a direction to find
    >a solution
    >
    >JAVA Code:
    >// Construct the header
    QName headerName = new QName(" http://ech.client.nl/vendor",
    >"Vendor");
    >SOAPHeaderElem ent headerElement = new SOAPHeaderEleme nt(headerName);
    >headerElement. setValue("ECH Gui");
    headerElement.s etMustUnderstan d(true);
    >
    >try {
    Message message = arg0.getCurrent Message();
    message.getSOAP Header().addChi ldElement(heade rElement);
    } catch (SOAPException se) {
    logger.error("K an niet SOAP header 'Vendor' toevoegen", se);
    }

    Comment

    • J. Dudgeon

      #3
      Re: How to add SOAP header to a SOAP message?

      You will need to add them manually before invoking the endpoint. Check out
      this MSDN page for the answer:
      http://msdn.microsoft.com/library/de...classtopic.asp

      You'll need to know what the SOAP headers look like so that you can create
      SoapHeader derived classes and then add instances of those classes to the
      SoapHeaderColle ction. You will need to use the SoapHeaderAttri bute as well.

      Hope that helps.

      "Peter van der veen" wrote:
      To be more precisely.
      >
      The webservice i call is not a .NET webservice.
      In the WSDL are no header elements defined.
      >
      To simplify the question.
      >
      I call a webservice and i want to add an SOAP header (with a
      headerelement and a value) to the outgoing message.
      >
      On Wed, 08 Nov 2006 10:18:22 +0100, Peter van der veen <wrote:
      >
      Hi

      I have the following problem.

      I'm calling a webservice from within a VB.net 2005 Windows program.
      For this i got a WSDL file and loaded that in VB.
      Until now i just call the webservice and everything works OK.

      Now i need to add an extra attribute/header element to the SOAP header
      before i contact the webservice.
      The webservice needs this to be in the SOAP header.

      Where and how do i do this? I have no clue at all.

      From the company that runs the webservice i got an example code in
      Java, but i have no idea where this had to be placed.


      Hope that soemone can help me or can direct me in a direction to find
      a solution

      JAVA Code:
      // Construct the header
      QName headerName = new QName(" http://ech.client.nl/vendor",
      "Vendor");
      SOAPHeaderEleme nt headerElement = new SOAPHeaderEleme nt(headerName);
      headerElement.s etValue("ECH Gui");
      headerElement.s etMustUnderstan d(true);

      try {
      Message message = arg0.getCurrent Message();
      message.getSOAP Header().addChi ldElement(heade rElement);
      } catch (SOAPException se) {
      logger.error("K an niet SOAP header 'Vendor' toevoegen", se);
      }
      >
      >

      Comment

      • Peter van der veen

        #4
        Re: How to add SOAP header to a SOAP message?


        And that is just the problem.

        I want to add a SOAP header but the webservice is not exposing a
        header in the WSDL.



        On Wed, 8 Nov 2006 05:28:02 -0800, J. Dudgeon
        <JDudgeon@discu ssions.microsof t.comwrote:
        >You will need to add them manually before invoking the endpoint. Check out
        >this MSDN page for the answer:
        >http://msdn.microsoft.com/library/de...classtopic.asp
        >
        >You'll need to know what the SOAP headers look like so that you can create
        >SoapHeader derived classes and then add instances of those classes to the
        >SoapHeaderColl ection. You will need to use the SoapHeaderAttri bute as well.
        >
        >Hope that helps.
        >
        >"Peter van der veen" wrote:
        >
        >To be more precisely.
        >>
        >The webservice i call is not a .NET webservice.
        >In the WSDL are no header elements defined.
        >>
        >To simplify the question.
        >>
        >I call a webservice and i want to add an SOAP header (with a
        >headerelemen t and a value) to the outgoing message.
        >>
        >On Wed, 08 Nov 2006 10:18:22 +0100, Peter van der veen <wrote:
        >>
        >Hi
        >
        >I have the following problem.
        >
        >I'm calling a webservice from within a VB.net 2005 Windows program.
        >For this i got a WSDL file and loaded that in VB.
        >Until now i just call the webservice and everything works OK.
        >
        >Now i need to add an extra attribute/header element to the SOAP header
        >before i contact the webservice.
        >The webservice needs this to be in the SOAP header.
        >
        >Where and how do i do this? I have no clue at all.
        >
        >From the company that runs the webservice i got an example code in
        >Java, but i have no idea where this had to be placed.
        >
        >
        >Hope that soemone can help me or can direct me in a direction to find
        >a solution
        >
        >JAVA Code:
        >// Construct the header
        QName headerName = new QName(" http://ech.client.nl/vendor",
        >"Vendor");
        >SOAPHeaderElem ent headerElement = new SOAPHeaderEleme nt(headerName);
        >headerElement. setValue("ECH Gui");
        headerElement.s etMustUnderstan d(true);
        >
        >try {
        Message message = arg0.getCurrent Message();
        message.getSOAP Header().addChi ldElement(heade rElement);
        } catch (SOAPException se) {
        logger.error("K an niet SOAP header 'Vendor' toevoegen", se);
        }
        >>
        >>

        Comment

        • J. Dudgeon

          #5
          Re: How to add SOAP header to a SOAP message?

          My understanding of your problem is that you want to communicate with some
          Web service that you didn't author. This service doesn't expose SOAP headers
          in the WSDL but you know the layout and format of the header(s).

          If that is the case then the headers don't need to be defined in the WSDL.
          As long as the Web service is accepting and processing the SOAP headers
          correctly, then follow the instructions above and it should work.

          "Peter van der veen" wrote:
          >
          And that is just the problem.
          >
          I want to add a SOAP header but the webservice is not exposing a
          header in the WSDL.
          >
          >
          >
          On Wed, 8 Nov 2006 05:28:02 -0800, J. Dudgeon
          <JDudgeon@discu ssions.microsof t.comwrote:
          >
          You will need to add them manually before invoking the endpoint. Check out
          this MSDN page for the answer:
          http://msdn.microsoft.com/library/de...classtopic.asp

          You'll need to know what the SOAP headers look like so that you can create
          SoapHeader derived classes and then add instances of those classes to the
          SoapHeaderColle ction. You will need to use the SoapHeaderAttri bute as well.

          Hope that helps.

          "Peter van der veen" wrote:
          To be more precisely.
          >
          The webservice i call is not a .NET webservice.
          In the WSDL are no header elements defined.
          >
          To simplify the question.
          >
          I call a webservice and i want to add an SOAP header (with a
          headerelement and a value) to the outgoing message.
          >
          On Wed, 08 Nov 2006 10:18:22 +0100, Peter van der veen <wrote:
          >
          Hi

          I have the following problem.

          I'm calling a webservice from within a VB.net 2005 Windows program.
          For this i got a WSDL file and loaded that in VB.
          Until now i just call the webservice and everything works OK.

          Now i need to add an extra attribute/header element to the SOAP header
          before i contact the webservice.
          The webservice needs this to be in the SOAP header.

          Where and how do i do this? I have no clue at all.

          From the company that runs the webservice i got an example code in
          Java, but i have no idea where this had to be placed.


          Hope that soemone can help me or can direct me in a direction to find
          a solution

          JAVA Code:
          // Construct the header
          QName headerName = new QName(" http://ech.client.nl/vendor",
          "Vendor");
          SOAPHeaderEleme nt headerElement = new SOAPHeaderEleme nt(headerName);
          headerElement.s etValue("ECH Gui");
          headerElement.s etMustUnderstan d(true);

          try {
          Message message = arg0.getCurrent Message();
          message.getSOAP Header().addChi ldElement(heade rElement);
          } catch (SOAPException se) {
          logger.error("K an niet SOAP header 'Vendor' toevoegen", se);
          }
          >
          >
          >
          >

          Comment

          • Peter van der veen

            #6
            Re: How to add SOAP header to a SOAP message?

            I only know that i need to add a header with the name 'VENDOR' tha
            must be in the namespace "http://ech.client.nl/vendor"
            and that i have to give it a value.

            After that i need to attach that header to the SOAP message.

            But i'm just call a function in the WSDL so i do net see how to add
            such a header to the message.


            On Thu, 9 Nov 2006 01:02:01 -0800, J. Dudgeon
            <JDudgeon@discu ssions.microsof t.comwrote:
            >My understanding of your problem is that you want to communicate with some
            >Web service that you didn't author. This service doesn't expose SOAP headers
            >in the WSDL but you know the layout and format of the header(s).
            >
            >If that is the case then the headers don't need to be defined in the WSDL.
            >As long as the Web service is accepting and processing the SOAP headers
            >correctly, then follow the instructions above and it should work.
            >
            >"Peter van der veen" wrote:
            >
            >>
            >And that is just the problem.
            >>
            >I want to add a SOAP header but the webservice is not exposing a
            >header in the WSDL.
            >>
            >>
            >>
            >On Wed, 8 Nov 2006 05:28:02 -0800, J. Dudgeon
            ><JDudgeon@disc ussions.microso ft.comwrote:
            >>
            >You will need to add them manually before invoking the endpoint. Check out
            >this MSDN page for the answer:
            >http://msdn.microsoft.com/library/de...classtopic.asp
            >
            >You'll need to know what the SOAP headers look like so that you can create
            >SoapHeader derived classes and then add instances of those classes to the
            >SoapHeaderColl ection. You will need to use the SoapHeaderAttri bute as well.
            >
            >Hope that helps.
            >
            >"Peter van der veen" wrote:
            >
            >To be more precisely.
            >>
            >The webservice i call is not a .NET webservice.
            >In the WSDL are no header elements defined.
            >>
            >To simplify the question.
            >>
            >I call a webservice and i want to add an SOAP header (with a
            >headerelemen t and a value) to the outgoing message.
            >>
            >On Wed, 08 Nov 2006 10:18:22 +0100, Peter van der veen <wrote:
            >>
            >Hi
            >
            >I have the following problem.
            >
            >I'm calling a webservice from within a VB.net 2005 Windows program.
            >For this i got a WSDL file and loaded that in VB.
            >Until now i just call the webservice and everything works OK.
            >
            >Now i need to add an extra attribute/header element to the SOAP header
            >before i contact the webservice.
            >The webservice needs this to be in the SOAP header.
            >
            >Where and how do i do this? I have no clue at all.
            >
            >From the company that runs the webservice i got an example code in
            >Java, but i have no idea where this had to be placed.
            >
            >
            >Hope that soemone can help me or can direct me in a direction to find
            >a solution
            >
            >JAVA Code:
            >// Construct the header
            QName headerName = new QName(" http://ech.client.nl/vendor",
            >"Vendor");
            >SOAPHeaderElem ent headerElement = new SOAPHeaderEleme nt(headerName);
            >headerElement. setValue("ECH Gui");
            headerElement.s etMustUnderstan d(true);
            >
            >try {
            Message message = arg0.getCurrent Message();
            message.getSOAP Header().addChi ldElement(heade rElement);
            } catch (SOAPException se) {
            logger.error("K an niet SOAP header 'Vendor' toevoegen", se);
            }
            >>
            >>
            >>
            >>

            Comment

            • J. Dudgeon

              #7
              Re: How to add SOAP header to a SOAP message?

              That was already described in my previous post.

              1. Generate a Web service proxy as you normally do.

              2. Create a class that describes the SOAP header you will be sending:

              [XmlRoot(Namespa ce = "http://ech.client.nl/vendor")]
              public class VENDOR : SoapHeader
              {
              public string Value;
              }

              3. Add a public member variable to the proxy class named "vendorHead er":

              public VENDOR vendorHeader;

              leave it set to null for now.

              4. Modify the method you are invoking and add the following attribute to
              that method:

              [SoapHeader("ven dorHeader", Direction = SoapHeaderDirec tion.In)]

              5. Modify the body of the method call so that you create an instance of the
              member variable. Put this code before the "Invoke" code:

              vendorHeader = new VENDOR();
              vendorHeader.Va lue = "This is my value";

              --------------

              That's it.

              "Peter van der veen" wrote:
              I only know that i need to add a header with the name 'VENDOR' tha
              must be in the namespace "http://ech.client.nl/vendor"
              and that i have to give it a value.
              >
              After that i need to attach that header to the SOAP message.
              >
              But i'm just call a function in the WSDL so i do net see how to add
              such a header to the message.
              >
              >
              On Thu, 9 Nov 2006 01:02:01 -0800, J. Dudgeon
              <JDudgeon@discu ssions.microsof t.comwrote:
              >
              My understanding of your problem is that you want to communicate with some
              Web service that you didn't author. This service doesn't expose SOAP headers
              in the WSDL but you know the layout and format of the header(s).

              If that is the case then the headers don't need to be defined in the WSDL.
              As long as the Web service is accepting and processing the SOAP headers
              correctly, then follow the instructions above and it should work.

              "Peter van der veen" wrote:
              >
              And that is just the problem.
              >
              I want to add a SOAP header but the webservice is not exposing a
              header in the WSDL.
              >
              >
              >
              On Wed, 8 Nov 2006 05:28:02 -0800, J. Dudgeon
              <JDudgeon@discu ssions.microsof t.comwrote:
              >
              You will need to add them manually before invoking the endpoint. Check out
              this MSDN page for the answer:
              http://msdn.microsoft.com/library/de...classtopic.asp

              You'll need to know what the SOAP headers look like so that you can create
              SoapHeader derived classes and then add instances of those classes to the
              SoapHeaderColle ction. You will need to use the SoapHeaderAttri bute as well.

              Hope that helps.

              "Peter van der veen" wrote:

              To be more precisely.
              >
              The webservice i call is not a .NET webservice.
              In the WSDL are no header elements defined.
              >
              To simplify the question.
              >
              I call a webservice and i want to add an SOAP header (with a
              headerelement and a value) to the outgoing message.
              >
              On Wed, 08 Nov 2006 10:18:22 +0100, Peter van der veen <wrote:
              >
              Hi

              I have the following problem.

              I'm calling a webservice from within a VB.net 2005 Windows program.
              For this i got a WSDL file and loaded that in VB.
              Until now i just call the webservice and everything works OK.

              Now i need to add an extra attribute/header element to the SOAP header
              before i contact the webservice.
              The webservice needs this to be in the SOAP header.

              Where and how do i do this? I have no clue at all.

              From the company that runs the webservice i got an example code in
              Java, but i have no idea where this had to be placed.


              Hope that soemone can help me or can direct me in a direction to find
              a solution

              JAVA Code:
              // Construct the header
              QName headerName = new QName(" http://ech.client.nl/vendor",
              "Vendor");
              SOAPHeaderEleme nt headerElement = new SOAPHeaderEleme nt(headerName);
              headerElement.s etValue("ECH Gui");
              headerElement.s etMustUnderstan d(true);

              try {
              Message message = arg0.getCurrent Message();
              message.getSOAP Header().addChi ldElement(heade rElement);
              } catch (SOAPException se) {
              logger.error("K an niet SOAP header 'Vendor' toevoegen", se);
              }
              >
              >
              >
              >
              >
              >

              Comment

              Working...