小编典典
要用Java实现简单的SOAP客户端,可以使用SAAJ框架(JSE 1.6及更高版本附带):
带有Java附件API的SOAP(SAAJ)主要用于直接处理任何Web Service API幕后发生的SOAP请求/响应消息。它允许开发人员直接发送和接收肥皂消息,而不是使用JAX-WS。
参见下面使用SAAJ进行SOAP Web服务调用的工作示例(运行它!)。它称为此Web服务。
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 = "