SOAP Client in java

This article will teach you how to create a SOAP client in java. That is creating a client in java which requests soap server (no need to be in java) and get response from it. First create request message as follows:

You can add as many attribute as you want. Now time to create request message body.
Following body is made assuming that SOAP server where this client will connect will have a public service method called getResponse(name) available.

I have a problem when connect with this code because the webservice return the message with conten-type application/xml and trigger a Exception “Invalid conten-type: application/xml. Is this an error mesage instead of a SOAP Response? ” You know how to resolve this??

I tried this code with a web service generating XML response and worked perfect. You should check the request XML you are sending is valid at server side. It can be possible that either you are not sending any content or too long contents or content you are sending in request is not in valid format for the server. If you want me to debug the issue then you have to send web service address and other associated details run this program on my personal email id, if its feasible for you. You can find my email id on about page. I’ll still try to see if I can reproduce this error and let you know the update. Also telling line on which you are getting this exception will be a good help to debug it.

Being a novice with Java, and required to call a Web Service with very limited time to implement a solution, your post has proven to be BY FAR the most helpful bit of information I have come across in the last 20 hours of research. Thank you!

@harryjoy..
Thanks a ton for this wonderful post. This has immensely helped me(for me being a novice).
I have following questions. Could you please help me with this?
1. If an EndPoint(A wsdl url) is given, Is there a way I can populate the available requests in Java? (This feature is available in SOAP UI. If you provide wsdl url, it populates requests)
2. Can you please post your above post for this sample Web service available in this link. http://www.webservicemart.com/uszip.asmx?WSDL.