I'm trying to consume a Third Party web service, through a wsdl file provided. I would load the file locally from a Spring-J2EE based project underneath WEB-INF folder.
The wsdl might have more than one operation exposed. So I need a way to be able to choose the method to be called. I would also need to make use of a JaxbMarshaller.
Can anyone help with a code snippet for the same?
Thanks for the help.
Upvotes: 0
Views: 4051
Reputation: 437
This is the simple method for calling web service. For details Click here
public void createSoapActionCallBack(ValidateCardRequest validateCardRequest) {
//This is used to send header message
SoapActionCallback actionCallBack=new SoapActionCallback(soapAction);
try{
actionCallBack = new SoapActionCallback(SOAPACTION_DEFAULT_URL) {
public void doWithMessage(WebServiceMessage msg) {
SoapMessage smsg = (SoapMessage)msg;
SoapHeader soapHeader = smsg.getSoapHeader();
try{
//To send header message
StringSource headerSource = new StringSource("<UserCredentials xmlns='URL'>\n" +
"<userid>"+"ABCD"+"</userid>\n" +
"<password>"+"ABCD"+"</password>\n" +
"</UserCredentials>");
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.transform(headerSource, soapHeader.getResult());
smsg.setSoapAction(soapAction);
}catch(Exception e)
{
e.printStackTrace();
}
}
};
validateCardResponse = (FVValidateCardResponse) webServiceTemplate.marshalSendAndReceive(URL, validateCardRequest, actionCallBack);
} catch (Exception e) {
e.printStackTrace();
}
}
Upvotes: 0
Reputation: 403561
WebServiceTemplate, and Spring-WS generally, do not treat WSDL as the starting point. Rather, it's schema-oriented.
When you use WebServiceTemplate, you plug in the JaxmMarshaller, then invoke the marshalSendAndReceiver methods, passing in a SoapActionCallback which contains the SOAP Action you want to invoke. You can get the SOAP action URI from the WSDL. WebServiceTemplate will marshal your request, wrap it in a WSDL envelope with the SOAP action you specified, and fire it off.
If you want a framework that generates stubs from your WSDL, then Spring-WS is not for you.
Upvotes: 1