my dog learned polymorphism*
The moose likes Web Services and the fly likes need help to consume webservice in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "need help to consume webservice in Java" Watch "need help to consume webservice in Java" New topic
Author

need help to consume webservice in Java

Moieen Khatri
Ranch Hand

Joined: Nov 27, 2007
Posts: 144
Hi Experts,

I am new to webservices.I am trying to call wsdl file using standalone java class.

Please can someone help with the steps as to how can I consume wsdl webservice using java class?

Also,what setup do I need to have inorder to achieve the same?

Thanks



Kumar Raja
Ranch Hand

Joined: Mar 18, 2010
Posts: 516
    
    2

Hi Katri,

The process of invoking the webservice, that has been described in WSDL is as following.

1) Execute wsimport on the WSDL for the generation of artifacts, this would generate and JAXB Bindings, stubs etc.
2) In your client application, get a reference of Service.
3) Invoke getXXX on service object to obtain the reference to port.
4) Invoke the method on the port, which acts as a stub.

The other way of invoking service, is by using Dispatch, should you want to handle the XML messages directly and this works in both PAYLOAD and SOAPMessage mode.

If you look into metro, there is a detailed explanation of each steps.

All the best.


Regards
KumarRaja

Yogendra Joshi
Ranch Hand

Joined: Apr 04, 2006
Posts: 212
Hi Khatri,

I would recommend you to use Spring Web Services, Its easy to learn and its a superb way of accessing web services.

Here is the link for a sample web service application which I found very helpful when I was learning web services :
Spring Web Service Sample App

Let me know if you need any additional pointers to learn web services,

Have a Great time learning !!

Yogendra

Meri Zindagi Hain Tab Tak.. Jab Tak Tera Sahara.... Har Taraf Tu Hi Tu Hain SAI Tera Hi Hain Nazara.....
Moieen Khatri
Ranch Hand

Joined: Nov 27, 2007
Posts: 144
Thanks for the response.

I generated the stubs using the below command:

wsimport -p <package - name> -s <source> -d <destination> WSDL URL


Now I am trying to call the method using Java standalone class.

My question is in order to consume the webservice do I need to have a client configuration file which will have the reference to the wsdl url along with the stub code?

Please provide your valuable feedback

Thanks
Moieen
Kumar Raja
Ranch Hand

Joined: Mar 18, 2010
Posts: 516
    
    2

Moieen Khatri wrote:Thanks for the response.

I generated the stubs using the below command:

wsimport -p <package - name> -s <source> -d <destination> WSDL URL


Now I am trying to call the method using Java standalone class.

My question is in order to consume the webservice do I need to have a client configuration file which will have the reference to the wsdl url along with the stub code?

Please provide your valuable feedback

Thanks
Moieen


What configuration file are you referring to, if you are using JAX-WS as I suggested, no configuration file is needed. What are the artifacts that were generated when you did wsimport.

Out of those, you will find a class that extends Service class. This is a reference to your service, now you will invoke one of the getXXX methods to get an reference of port. Once you get port, you can invoke the method.
Moieen Khatri
Ranch Hand

Joined: Nov 27, 2007
Posts: 144
Hi Kumar,

You are correct.On executing wsimport command the artifacts got generated(Java classes were generated out of which there is a class which extends Service Class)

I got the ports using the below code:



I now have the URL from the port

How can I invoke the business method now using the above port.Kindly advice.

Please can you post some sample code which can help me implement the above?

Thanks
Moieen
Kumar Raja
Ranch Hand

Joined: Mar 18, 2010
Posts: 516
    
    2

I have almost forgot about this thread.

Did you find your code working Moieen ?

Once you have the service object, you get a port by invoking getXXXX(), which returns you a stub and you can invoke the methods defined for that port?


Say fro eg, in your WSDL, if the service name CustomerService and the PortType is CustomerPort and have an operation getCustomer(). Your code would be something like below

CustomerService service = new CustomerService () //This is one of the client side artifacts, that was generated using wsimport.

CustomerPort port = service.getCustomerPort();

Customer obj = port.getCustomer();




I
kannan Chocku
Greenhorn

Joined: Mar 13, 2013
Posts: 8
Hi,

I'm new to web services. I have got wsdl url.

1. I used > wsimport -keep -verbose http://....?wsdl
2. It generate java classes, interface & service Implementation class which extends service
3. I created the web service client class in which I acess the getXXXport() in serviceImplementation class to call the remote method
4. I also created interfaceImplementation class(Is this right??? In this class I implemented the interface(which is auto generated))

Problem is that I couldn't see some particular schema type java class which is present in wsdl
without that schema type class I wont be able to build the response

Please guide me if I'm wrong in these steps & also point out why I couldn't see schema type java file when I use wsimport

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: need help to consume webservice in Java
 
Similar Threads
applicationcontext.xml
Trying to use wsdl2java generated classes
Jboss 5.0 throwing “Endpoint does not contain operation meta data for http://services.upc.tecno.com
How to consume .net webservice which is created using wsdl in java?
AXIS 1.4.1 compatability with Statefull Web Services