问题
我正试图在JAVA中找到一个带有工作服务的简单(ha)SOAP示例,我似乎发现的任何东西都不起作用。
我试过这个578312314来自这个example但是它只是不工作,它要求我放一个正斜杠但它在那里并没有发生任何事情。
那么有谁知道任何SOAP示例链接,我可以下载/请求和搞乱?
谢谢你的帮助。
#1 热门回答(195 赞)
要在Java中实现简单的SOAP客户端,你可以使用SAAJ框架(它随JSE 1.6及更高版本一起提供):
SOAP with Attachments API for Java(SAAJ)主要用于直接处理任何Web Service API中幕后发生的SOAP请求/响应消息。它允许开发人员直接发送和接收soap消息,而不是使用JAX-WS。
请参阅下面的使用SAAJ的SOAP Web服务调用的工作示例(运行它!)。它叫this web service。
import javax.xml.soap.*;
public class SOAPClientSAAJ {
// SAAJ - SOAP Client Testing
public static void main(String args[]) {
/*
The example below requests from the Web Service at:
http://www.webservicex.net/uszip.asmx?op=GetInfoByCity
To call other WS, change the parameters below, which are:
- the SOAP Endpoint URL (that is, where the service is responding from)
- the SOAP Action
Also change the contents of the method createSoapEnvelope() in this class. It constructs
the inner part of the SOAP envelope that is actually sent.
*/
String soapEndpointUrl = "http://www.webservicex.net/uszip.asmx";
String soapAction = "http://www.webserviceX.NET/GetInfoByCity";
callSoapWebService(soapEndpointUrl, soapAction);
}
private static void createSoapEnvelope(SOAPMessage soapMessage) throws SOAPException {
SOAPPart soapPart = soapMessage.getSOAPPart();
String myNamespace = "myNamespace";
String myNamespaceURI = "http://www.webserviceX.NET";