我在我的本地apache tomcat上运行了一个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 ???
答案 0 :(得分:0)
不起作用
异常,错误消息,没有通话,......?
乍一看,我看不到任何明显的东西,但是因为你正在使用Eclipse,在Eclipse下激活TCP Monitor,通过从Eclipse运行你的程序发出你的调用并检查线路上发送的内容。
答案 1 :(得分:0)
getContentDescription()&#34;返回:描述此消息内容的String;如果未设置描述,则返回null&#34;而不是你的消息的内容。
试试这个:
ByteArrayOutputStream out = new ByteArrayOutputStream();
reply.writeTo(out);
System.out.println("Response: "+out.toString());