1

重複の可能性:
WebサービスリクエストにカスタムSoapヘッダーを追加する

WSDLファイルから生成されたJavaクライアントを使用してWebサービスを呼び出そうとしています。<soap:Header>内部に追加する必要があります<soap:Envelope>。eclipseでクライアントを生成してサービスを呼び出したとき、リクエストメッセージは次のとおりでした。

    <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"  xmlns:tem="http://tempuri.org/">
    <soap:Body>
      <tem:GetEntityXml>
         <!--Optional:-->
         <tem:entityGuid>f949d2fe-d5a2-4115-a920-e85343adcf1a</tem:entityGuid>
      </tem:GetEntityXml>
   </soap:Body>
</soap:Envelope>

私がこのように望むところは、

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/">
<soap:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
  <wsa:Action>http://tempuri.org/xxx/HelloWorld</wsa:Action><wsa:To>https://xxx/yyy.svc</wsa:To>
</soap:Header>
   <soap:Body>
      <tem:GetEntityXml>
         <!--Optional:-->
         <tem:entityGuid>f949d2fe-d5a2-4115-a920-e85343adcf1a</tem:entityGuid>
      </tem:GetEntityXml>
   </soap:Body>
</soap:Envelope>

_call.invoke()メソッドの前にSOAPエンベロープを変更しようとしました。

org.apache.axis.message.SOAPHeaderElement she=new org.apache.axis.message.SOAPHeaderElement("http://www.w3.org/2005/08/addressing",null); 
        she.addNamespaceDeclaration("wsa","http://www.w3.org/2005/08/addressing");


        SOAPElement node=she.addChildElement("Action","wsa");
        node.addTextNode("http://tempuri.org/xxx/HelloWorld");
        System.out.println("2");
        SOAPElement node2=she.addChildElement("To","wsa");
        node2.addTextNode("https://xxx/yyy.svc");

        _call.getMessageContext().getCurrentMessage().getSOAPEnvelope().addHeader(she);;
        System.out.println(she);
        _call.addHeader(she);

私はWebサービスに非常に慣れていないので、あらゆる提案を歓迎します。

必要に応じてヘッダーの作成とフォーマットを手伝ってください。

4

0 に答える 0