我有我的本地Apache Tomcat上運行的Web服務。我可以通過SoapUI成功地與之通話。但是,當我用Java編寫客戶端時,它不會給我一個迴應!製作到Web服務的調用通過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工作???
「不工作」=>我得到響應消息爲 「零」。你看SYSOUT末它打印「迴應:空」,哦,順便說一句,我使用「MyEclipse的」和我似乎無法找到TCP/IP監控下的喜好! – tsure 2012-07-23 17:37:27