0

ローカルのapacheTomcatでWebサービスを実行しています。SoapUIを介して正常に通信できます。ただし、Javaでクライアントを作成しても、応答がありません。

クライアントコードは次のとおりです。

    SOAPConnectionFactory myFct = SOAPConnectionFactory.newInstance();
    SOAPConnection myCon = myFct.createConnection();
    MessageFactory myMsgFct = MessageFactory.newInstance();
    SOAPMessage message = myMsgFct.createMessage();
    SOAPPart mySPart = message.getSOAPPart();
    SOAPEnvelope myEnvp = mySPart.getEnvelope();
    SOAPBody body = myEnvp.getBody();
    Name bodyName = myEnvp.createName("Ping", "ws","http://ws.myeclipseide.com/");
    SOAPBodyElement gltp = body.addBodyElement(bodyName);
    Name myContent1 = myEnvp.createName("arg0");
    SOAPElement mySymbol1 = gltp.addChildElement(myContent1);
    mySymbol1.addTextNode("test");
    message.saveChanges();

    URLEndpoint endPt = new URLEndpoint("http://localhost:8080/PingWebService/StringPingPort?WSDL");
    SOAPMessage reply = myCon.call(message, endPt);
    myCon.close();
    System.out.println("Response: "+reply.getContentDescription());

soapUIを介した呼び出しは次のようになります。

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.myeclipseide.com/">
   <soapenv:Header/>
   <soapenv:Body>
      <ws:Ping>
         <!--Optional:-->
         <arg0>testing this</arg0>
      </ws:Ping>
   </soapenv:Body>
</soapenv:Envelope>

なぜそれがJavaを介して機能しないのか考えてみてください。

4

2 に答える 2

0

動作しません

例外、エラーメッセージ、呼び出しなし、...?

一見、明らかなことは何もわかりませんが、Eclipseを使用しているので、EclipseでTCPモニターをアクティブにし、Eclipseからプログラムを実行して呼び出しを発行し、ネットワーク上で何が送信されるかを確認します。

于 2012-07-21T05:30:06.620 に答える
0

getContentDescription() 「戻り値: このメッセージの内容を説明する文字列、または説明が設定されていない場合は null」であり、メッセージの内容ではありません。

これを試して:

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    reply.writeTo(out); 
    System.out.println("Response: "+out.toString());
于 2012-08-06T01:21:43.940 に答える