如何在SOAP Web客户端

时间:2018-04-11 21:05:46

标签: java web-services soap payload

我试图弄清楚如何使用从wsdl文件生成的Web服务。在这个项目中,我将使用生成的webservice客户端发送请求。界面如下所示:

public interface IConnectService {
public void processMessage(
    @WebParam(name = "payload", mode = 
WebParam.Mode.INOUT)
    Holder<Payload> payload);
}

客户端是这样的:

public class ConnectService
extends Service
{
private final static URL CONNECTSERVICE_WSDL_LOCATION;
private final static WebServiceException CONNECTSERVICE_EXCEPTION;
private final static QName CONNECTSERVICE_QNAME = new 
QName("http://xxxxxx-asi.com/services", "ConnectService");
static {
    URL url = null;
    WebServiceException e = null;
    try {
        url = new URL("http://localhost/wsdl/xxxxx"); 
    } catch (MalformedURLException ex) {
        e = new WebServiceException(ex);
    }
    CONNECTSERVICE_WSDL_LOCATION = url;
    CONNECTSERVICE_EXCEPTION = e;
 }

 public ConnectService() {
    super(__getWsdlLocation(), CONNECTSERVICE_QNAME);
 }

 public ConnectService(WebServiceFeature... features) {
    super(__getWsdlLocation(), CONNECTSERVICE_QNAME, features);
 }

 public ConnectService(URL wsdlLocation) {
    super(wsdlLocation, CONNECTSERVICE_QNAME);
 }

 public ConnectService(URL wsdlLocation, WebServiceFeature... 
features) {
    super(wsdlLocation, CONNECTSERVICE_QNAME, features);
}

 public ConnectService(URL wsdlLocation, QName serviceName) {
    super(wsdlLocation, serviceName);
  }

 public ConnectService(URL wsdlLocation, QName serviceName, 
 WebServiceFeature... features) {
    super(wsdlLocation, serviceName, features);
}
@WebEndpoint(name = "BasicHttpBinding_IConnectService")
public IConnectService getBasicHttpBindingIConnectService() {
    return super.getPort(new QName("http://xxxxxxx- 
asi.com/services", "BasicHttpBinding_IConnectService"), 
IConnectService.class);
}

@WebEndpoint(name = "BasicHttpBinding_IConnectService")
public IConnectService 
getBasicHttpBindingIConnectService(WebServiceFeature... features) {
    return super.getPort(new QName("http://xxxxxx-asi.com/services", 
"BasicHttpBinding_IConnectService"), IConnectService.class, 
features);
}

private static URL __getWsdlLocation() {
    if (CONNECTSERVICE_EXCEPTION!= null) {
        throw CONNECTSERVICE_EXCEPTION;
    }
    return CONNECTSERVICE_WSDL_LOCATION;
 }

}

soap请求消息结构将如下图所示:enter image description here

所以我的问题是如何使用接口方法使用客户端进行包含soapmessage的调用?据我所知,Holder对象只能接受Payload对象,这是ProcessMessege的一个小元素(如结构所示),而ProcessMessage是SOAP主体的一个小元素。我需要将安全凭证放在SOAP标头中,我已经这样做了。所以现在如果我使用webservice方法,我只能传递有效负载对象,但Web服务器将不接受请求,因为有效负载部分内没有凭据。任何人都可以帮忙解决这个问题?我真的很感谢你的帮助!

1 个答案:

答案 0 :(得分:0)

我通过使用soapmessage处理程序和处理程序解析器解决了这个问题。处理程序可以在soap标头中插入凭据,并修改soap主体以满足我对soap消息的所有要求。