0

How to add header to soap request

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:bur="http://test.com">
   <soapenv:Header>
      <bur:AuthHeader>
          <Username></Username>
         <Password></Password>
         <REQUEST_ID>1</REQUEST_ID>
      </bur:AuthHeader>
   </soapenv:Header>
   <soapenv:Body>
      <bur:Add>
         <AddReqDto>
            <a>10</a>
            <b>20</b>
          /AddReqDto>
      </bur:Add>
   </soapenv:Body>
</soapenv:Envelope>

Then Net Bean generated code. It look like this:

SomeService service = new SomeService

    QName portQName = new QName("http://services.somehost.com/" , "someservice");
    String req = "<Add  xmlns=\"http://services.somehost.com/\"><AddDto>1</AddReqDto></Add>";

    try { // Call Web Service Operation

        Dispatch<Source> sourceDispatch = null;
        sourceDispatch = service.createDispatch(portQName, Source.class, Service.Mode.PAYLOAD);
        Source result = sourceDispatch.invoke(new StreamSource(new StringReader(req)));
        System.out.print( result.toString());
    } catch (Exception ex) {
        // TODO handle custom exceptions here
        ex.printStackTrace();
    }

So how to add this header to my SOAP request?

piyushj
  • 1,546
  • 5
  • 21
  • 29
Yousaf Jan
  • 11
  • 2
  • Possible duplicate of [Add WSSE SOAP Header to Web Reference](http://stackoverflow.com/questions/14869602/add-wsse-soap-header-to-web-reference) – mnwsmit Jun 10 '16 at 07:50
  • I don't think it's a duplicate, because the referenced question is for c# not java and it's about WS-Security headers not normal soap headers, which are two complete different things IMHO. – Frank Jun 10 '16 at 10:22

0 Answers0