来自WSDL的Spring-ws客户端

wun*_*tee 2 wsdl spring-ws

我使用spring-ws创建了一个POX客户端(从XSD生成的jaxb2),但是对于如何创建SOAP客户端(从WSDL生成)感到困惑.我正在使用wsimport生成存根,但是看起来这对于使用spring-ws来说太过分了.存根实际上处理传输,与POX客户端一样,spring处理传输.所以,我的问题是:是否可以通过wsimport或jaxb2(如POX客户端)生成传输对象,或者我在WebServiceTemplate中调用/发送什么?

Axe*_*ine 5

是的你可以.

确保您的XSD是从wsdl导入的,而不是嵌入在wsdl中.

在你的xsd指向xjc(来自Jaxb2)并让它生成你的类.

现在检查您的架构.

如果您的请求和响应元素具有嵌入的复杂类型,请使用:

RequestElement requestElement = new RequestElement();
ResponseElement responseElement = (ResponseElement) webServiceTemplate.marshalSendAndReceive(requestElement);
Run Code Online (Sandbox Code Playgroud)

否则(引用复杂类型)使用此:

RequestType requestType = new RequestType();
JAXBElement<RequestType> request = new ObjectFactory().createRequestType(requestType);
ResponseType responseType = ((JAXBElement<ResponseType>) webServiceTemplate.marshalSendAndReceive(request)).getValue();
Run Code Online (Sandbox Code Playgroud)

RequestElement,ResponseElement,RequestType和ResponseType当然只是示例.用你的模式生成的任何类Xjc替换它们.