srinivasp19
asked on
java client code to send a SOAP request and read response from a WSDL url.
A SOAP webservice hosted on a server,
I know wsdl url and what tags to set in request.
Requirement:
1) I want to set some fields(tags) of soap request.
2) send the request
3) read the response.
Please point me to the java code to implement the above.
Thanks in Advance
I know wsdl url and what tags to set in request.
Requirement:
1) I want to set some fields(tags) of soap request.
2) send the request
3) read the response.
Please point me to the java code to implement the above.
Thanks in Advance
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Set the username/password in the message sender, then add it to the soap header too
here is a sample code:
//Set the username/password in the message sender
WebServiceTemplate webService = new WebServiceTemplate();
UsernamePasswordCredential s credentials = new UsernamePasswordCredential s("<userna me>","<pas sword>");
CommonsHttpMessageSender msgSender = new CommonsHttpMessageSender() ;
msgSender.setCredentials(c redentials );
webService.setMessageSende r(msgSende r);
......
.......
//add it to the soap header
webService.sendSourceAndRe ceiveToRes ult(reques tPayload, new WSSEHeaderWebServiceMessag eCallback( "<username >","<passw ord>"), responseResult);
here is a sample code:
//Set the username/password in the message sender
WebServiceTemplate webService = new WebServiceTemplate();
UsernamePasswordCredential
CommonsHttpMessageSender msgSender = new CommonsHttpMessageSender()
msgSender.setCredentials(c
webService.setMessageSende
......
.......
//add it to the soap header
webService.sendSourceAndRe
you can also Eclipse's webservice client wizard, just specify the wsdl and it does the rest, it auto-geneterates the interface/proxy that you will need to instantiate. For example it will generate a ServiceProxy which would contain the methods that the webservice host has exposed. Another helpful option when you use this, you can opt to generate sample jsp files that you can deploy and will show you how the ServicePRoxy is used. I've used this 3 times already in my career, the last one is for integration with Salesforce.
btw, It uses axis behind the scenes.
http://www.eclipse.org/webtools/community/tutorials/BottomUpAxis2WebService/bu_tutorial.html
btw, It uses axis behind the scenes.
http://www.eclipse.org/webtools/community/tutorials/BottomUpAxis2WebService/bu_tutorial.html
ASKER
Thank you for the reply.
I forgot to mention that the wsdl url is https.
How to add username and password for authentication in the SOAP request?.
I Prefer the Java code :
which takes WSDL URL with authentication as input and get SOAP request xml, (similar to SOAPUI tool)
with the SOAP request xml object , I should set the required tag(paramenter of exposed service) and send request.
Thanks in advance.