aspose file tools*
The moose likes Web Services and the fly likes Confusion in writing web service client + jax-ws Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Confusion in writing web service client + jax-ws" Watch "Confusion in writing web service client + jax-ws" New topic
Author

Confusion in writing web service client + jax-ws

Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 757
Hi,

I've created a web service using jax-ws (StockQuoteService) as shown in the link bellow.

http://today.java.net/pub/a/today/2006/06/13/web-services-with-jax-ws-2.0.html

I've also deployed the service and service is running fine.

but while writing client code The article says

The astute reader will have noticed two new classes: StockQuote and StockQuoteService.


but i'm not able to find any of the classes, I have got two more classes as bellow

getQuote & getQuoteResponse

I'm not able to understand, it is becoming bit confusing. can anybody explain me in little detail.

Thanks !

My Service Implementation class

StockQuoteImpl.java



two files generated after wsgen command

GetQuote.java


and GetQuoteResponse.java



WSDL file


[ February 20, 2008: Message edited by: Jigar Naik ]

Jigar Naik


Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
Read a bit further:
The astute reader will have noticed two new classes: StockQuote and StockQuoteService. ... You generate these classes, and all of the other classes that the client needs, using the wsimport tool


It's wsimport that generates these classes, not wsgen.

GetQuote.java and GetQuoteResponse.java are the Java object versions of the XML elements {http://india/}getQuote and {http://india/}getQuoteResponse respectively, found in the schema at
Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 757
yes, i missed one step of wsimport.

now that i will be able to write client code but there are 2 questions in my mind.

1) is my sequence correct ? (through service endpoint implementation class, wsgen generate required classes, and than wsgen will generate wsdl file linked to the wsgen generated classes.) What are these classes called(I'm talking about classes generated through wsgen, not wsimport) ?

2) and what wsimport does ? i guess it generate stub which are again few more classes. What are they used for ?

Thanks in anticipation,

[ February 20, 2008: Message edited by: Jigar Naik ]
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
You'll have a much easier time understanding the "basics" if you simply use Java SE 6.



To build:


To run:


Now with the web browser check http://localhost:8080/wsdemo/stock_quote?wsdl and http://localhost:8080/wsdemo/stock_quote?xsd=1

Control-C exits the com.sun.net.httpserver.HttpServer

wsgen creates:
com/wakaleo/tutorials/webservices/server/jaxws/GetQuote.class JVM server object version of {http://server.webservices.tutorials.wakaleo.com}getQuote
com/wakaleo/tutorials/webservices/server/jaxws/GetQuoteResponse.class JVM server object version of {http://server.webservices.tutorials.wakaleo.com}getQuoteResponse


The client code


To build (while com.wakaleo.tutorials.webservices.server.Main is running in another console window to present the WSDL):


To run (while com.wakaleo.tutorials.webservices.server.Main is running in another console window):


Output:


wsimport creates:
com/wakaleo/tutorials/webservices/client/GetQuote.class JVM client object version of {http://server.webservices.tutorials.wakaleo.com}getQuote
com/wakaleo/tutorials/webservices/client/GetQuoteResponse.class JVM client object version of {http://server.webservices.tutorials.wakaleo.com}getQuoteResponse
com/wakaleo/tutorials/webservices/client/ObjectFactory.class most likely the code responsible for Object/XML marshalling unmarshalling
com/wakaleo/tutorials/webservices/client/package-info.class metadata?
com/wakaleo/tutorials/webservices/client/StockQuote.class Class implementing the service port
com/wakaleo/tutorials/webservices/client/StockQuoteService.class Class implementing the service


This is an example of "Contract Last Development" - i.e. the Java server code is written first and the service contract (WSDL) is generated from that.
I personally prefer Contract First Development - i.e. design the artifact that the client actually sees (the WSDL) first and then use the contract to generate some server stubs.
[ February 21, 2008: Message edited by: Peer Reynders ]
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
Once you get the above working it's time to see what is going on.

Download java.net tcpmon and start it up in a third console window while the web service is running:


Configure TCP Monitor:
Local Port: 8090
Server Name: 127.0.0.1
ServerPort: 8080
click Add monitor.

To be able to see the request/response parts the client needs to go to port 8090 instead of 8080. To accomplish that we need a modified WSDL for the client:


Now modify the client code to use the modified WSDL:


Rebuild the client and start it up while the web service and tcpmon are running. In tcpmon you should see the request and response.

HTTP/SOAP Request:


Basically a com.wakaleo.tutorials.webservices.client.GetQuote instance is marshalled on the client side to

That XML is unmarshalled on the service side to a com.wakaleo.tutorials.webservices.server.jaxws.GetQuote instance. The service processes the request and creates a com.wakaleo.tutorials.webservices.server.jaxws.GetQuoteResponse instance which is marshalled to

which is included as the SOAP payload in the HTTP/SOAP Response:


On the client side the SOAP payload is unmarshalled to com.wakaleo.tutorials.webservices.client.GetQuoteResponse. The StockQuote instance extracts the return value from the GetQuoteResponse instance and uses it as the return value for your port.getQuote() call. It was StockQuote that created the GetQuote instance in the first place to send the stock ticker symbol to the service.
[ February 21, 2008: Message edited by: Peer Reynders ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Confusion in writing web service client + jax-ws