How to add SOAP header to a SOAP message?

Discussion in 'ASP .Net Web Services' started by Peter van der veen, Nov 8, 2006.

  1. 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");
    SOAPHeaderElement headerElement = new SOAPHeaderElement(headerName);
    headerElement.setValue("ECH Gui");
    headerElement.setMustUnderstand(true);

    try {
    Message message = arg0.getCurrentMessage();
    message.getSOAPHeader().addChildElement(headerElement);
    } catch (SOAPException se) {
    logger.error("Kan niet SOAP header 'Vendor' toevoegen", se);
    }
    Peter van der veen, Nov 8, 2006
    #1
    1. Advertising

  2. 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");
    >SOAPHeaderElement headerElement = new SOAPHeaderElement(headerName);
    >headerElement.setValue("ECH Gui");
    > headerElement.setMustUnderstand(true);
    >
    >try {
    > Message message = arg0.getCurrentMessage();
    > message.getSOAPHeader().addChildElement(headerElement);
    > } catch (SOAPException se) {
    > logger.error("Kan niet SOAP header 'Vendor' toevoegen", se);
    > }
    Peter van der veen, Nov 8, 2006
    #2
    1. Advertising

  3. Peter van der veen

    J. Dudgeon Guest

    You will need to add them manually before invoking the endpoint. Check out
    this MSDN page for the answer
    http://msdn.microsoft.com/library/d...esprotocolssoapheadercollectionclasstopic.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
    SoapHeaderCollection. You will need to use the SoapHeaderAttribute 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");
    > >SOAPHeaderElement headerElement = new SOAPHeaderElement(headerName);
    > >headerElement.setValue("ECH Gui");
    > > headerElement.setMustUnderstand(true);
    > >
    > >try {
    > > Message message = arg0.getCurrentMessage();
    > > message.getSOAPHeader().addChildElement(headerElement);
    > > } catch (SOAPException se) {
    > > logger.error("Kan niet SOAP header 'Vendor' toevoegen", se);
    > > }

    >
    >
    J. Dudgeon, Nov 8, 2006
    #3
  4. 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
    <> wrote:

    >You will need to add them manually before invoking the endpoint. Check out
    >this MSDN page for the answer:
    >http://msdn.microsoft.com/library/d...esprotocolssoapheadercollectionclasstopic.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
    >SoapHeaderCollection. You will need to use the SoapHeaderAttribute 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");
    >> >SOAPHeaderElement headerElement = new SOAPHeaderElement(headerName);
    >> >headerElement.setValue("ECH Gui");
    >> > headerElement.setMustUnderstand(true);
    >> >
    >> >try {
    >> > Message message = arg0.getCurrentMessage();
    >> > message.getSOAPHeader().addChildElement(headerElement);
    >> > } catch (SOAPException se) {
    >> > logger.error("Kan niet SOAP header 'Vendor' toevoegen", se);
    >> > }

    >>
    >>
    Peter van der veen, Nov 9, 2006
    #4
  5. Peter van der veen

    J. Dudgeon Guest

    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
    > <> wrote:
    >
    > >You will need to add them manually before invoking the endpoint. Check out
    > >this MSDN page for the answer:
    > >http://msdn.microsoft.com/library/d...esprotocolssoapheadercollectionclasstopic.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
    > >SoapHeaderCollection. You will need to use the SoapHeaderAttribute 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");
    > >> >SOAPHeaderElement headerElement = new SOAPHeaderElement(headerName);
    > >> >headerElement.setValue("ECH Gui");
    > >> > headerElement.setMustUnderstand(true);
    > >> >
    > >> >try {
    > >> > Message message = arg0.getCurrentMessage();
    > >> > message.getSOAPHeader().addChildElement(headerElement);
    > >> > } catch (SOAPException se) {
    > >> > logger.error("Kan niet SOAP header 'Vendor' toevoegen", se);
    > >> > }
    > >>
    > >>

    >
    >
    J. Dudgeon, Nov 9, 2006
    #5
  6. 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
    <> wrote:

    >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
    >> <> wrote:
    >>
    >> >You will need to add them manually before invoking the endpoint. Check out
    >> >this MSDN page for the answer:
    >> >http://msdn.microsoft.com/library/d...esprotocolssoapheadercollectionclasstopic.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
    >> >SoapHeaderCollection. You will need to use the SoapHeaderAttribute 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");
    >> >> >SOAPHeaderElement headerElement = new SOAPHeaderElement(headerName);
    >> >> >headerElement.setValue("ECH Gui");
    >> >> > headerElement.setMustUnderstand(true);
    >> >> >
    >> >> >try {
    >> >> > Message message = arg0.getCurrentMessage();
    >> >> > message.getSOAPHeader().addChildElement(headerElement);
    >> >> > } catch (SOAPException se) {
    >> >> > logger.error("Kan niet SOAP header 'Vendor' toevoegen", se);
    >> >> > }
    >> >>
    >> >>

    >>
    >>
    Peter van der veen, Nov 14, 2006
    #6
  7. Peter van der veen

    J. Dudgeon Guest

    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(Namespace = "http://ech.client.nl/vendor")]
    public class VENDOR : SoapHeader
    {
    public string Value;
    }

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

    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("vendorHeader", Direction = SoapHeaderDirection.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.Value = "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
    > <> wrote:
    >
    > >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
    > >> <> wrote:
    > >>
    > >> >You will need to add them manually before invoking the endpoint. Check out
    > >> >this MSDN page for the answer:
    > >> >http://msdn.microsoft.com/library/d...esprotocolssoapheadercollectionclasstopic.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
    > >> >SoapHeaderCollection. You will need to use the SoapHeaderAttribute 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");
    > >> >> >SOAPHeaderElement headerElement = new SOAPHeaderElement(headerName);
    > >> >> >headerElement.setValue("ECH Gui");
    > >> >> > headerElement.setMustUnderstand(true);
    > >> >> >
    > >> >> >try {
    > >> >> > Message message = arg0.getCurrentMessage();
    > >> >> > message.getSOAPHeader().addChildElement(headerElement);
    > >> >> > } catch (SOAPException se) {
    > >> >> > logger.error("Kan niet SOAP header 'Vendor' toevoegen", se);
    > >> >> > }
    > >> >>
    > >> >>
    > >>
    > >>

    >
    >
    J. Dudgeon, Nov 14, 2006
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. rabbits77
    Replies:
    0
    Views:
    867
    rabbits77
    Feb 26, 2004
  2. andrewzzz
    Replies:
    2
    Views:
    675
    andrewzzz
    Nov 13, 2008
  3. mlt
    Replies:
    2
    Views:
    834
    Jean-Marc Bourguet
    Jan 31, 2009
  4. Henning Panke
    Replies:
    0
    Views:
    142
    Henning Panke
    Jun 22, 2007
  5. Chris Gunnels
    Replies:
    2
    Views:
    171
    Jeremy Hinegardner
    Feb 4, 2010
Loading...

Share This Page