如何在java中添加custome soap标头

时间:2016-06-10 07:37:19

标签: java soap

如何向soap请求添加标题

<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>

然后Net Bean生成代码。它看起来像这样:

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();
    }

那么如何将此标头添加到我的SOAP请求中呢?

0 个答案:

没有答案