Spring-ws client from WSDL
I have created a POX client (generated from jaxb2 from XSD) using spring-ws, but am confused as to how to create a SOAP client (generated from a WSDL). I am using wsimpor开发者_如何学Got to generate stubs, but it seems like this goes 1 step too far for use with spring-ws. The stub actually handles the transport, where as with the POX client, spring handles the transport. So, my question is: is it possible to generate just the transport objects through wsimport, or jaxb2 (like the POX client), or what do I call/send in the WebServiceTemplate?
Yes, you can.
Make sure your XSD is imported from and not embedded in your wsdl.
Point xjc (from Jaxb2) at your xsd and let it generate your classes.
Now check your schema.
If your request and response element have embedded complex types use this:
RequestElement requestElement = new RequestElement();
ResponseElement responseElement = (ResponseElement) webServiceTemplate.marshalSendAndReceive(requestElement);
otherwise (referenced complex types) use this:
RequestType requestType = new RequestType();
JAXBElement<RequestType> request = new ObjectFactory().createRequestType(requestType);
ResponseType responseType = ((JAXBElement<ResponseType>) webServiceTemplate.marshalSendAndReceive(request)).getValue();
RequestElement, ResponseElement, RequestType and ResponseType are of course just examples. Substitute them with whatever classes Xjc generated from your schema.
精彩评论