This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
i am sharing a java client code from java web services up and running by MARTIN KALIN.I have few doubts related to web service invocation from this client code.
I would like to mention that I am using jdk 1.6 which as per to the book has got built in support for JAX-WS.
The web service being invoked has two operations:
1. First method in the service returns current DATE as String and takes nothing as an argument.
2. Second method returns a long vaue as time elapsed in milliseconds till now.
DOUBTS I have not generated and kept any STUBS on my client end and still i am able to invoke the web service successfully.
How is instance of a class implementing TiimeServer interface getting created when their is no definition of the class implementing that interface on the client side.
how are soap messages getting created as i am not able to see any class or related artifact which can do so?
Please elaborate these points. I know this would be basic questions for experienced members in the forum but as i am a beginner please elaborate it.
I would request IVAN KRIZGAN as i found him more active in the forum among others to explain the fact.
OK, I am back to try to answer your question:
Why don't you need any generated artifacts in the example you showed? When you create the Service object on row 11 you provide two things:
a) An URL from which the WSDL of the service you want to invoke can be retrieved.
b) The fully qualified name of the WSDL <service> element representing the service you want to invoke.
What happens is something along these lines:
- The WSDL is retrieved.
- The <service> element in the WSDL which you want to invoke is looked up using the QName you provided.
- The <portType> element for the service is located, by first going to the WSDL <binding> element for the <service> in question and then locating the <portType> specified in the <binding> element.
- When you on line 14 retrieve the proxy for the service, a proxy is created using the provided interface.
- The methods in the provided interface are matched to the <operation> elements in the <portType> element retrieved in the above step.
- JAXB beans are generated for the request and response messages.
- The address of the web service is retrieved from the <service> element.
This is the address to which web service requests in the form of SOAP messages are sent to when the service is invoked.
- When you invoke a method on the proxy, like in line 16, the proxy populates appropriate JAXB bean and marshals it to XML and sends the request in a SOAP envelope to the address retrieved above.
- It also receives the response, unmarshals it, retrieves the return data and returns it to the invoker of the proxy.
The only point which raises question in my mind is
When you on line 14 retrieve the proxy for the service, a proxy is created using the provided interface.
how is the definition of the class implementing the end point interface getting created at client side in order to get an instance of that class which you call
Joined: Oct 04, 2006
Sorry, I did not express myself carefully.
I should have written:
When you on line 14 retrieve the web service proxy, a class that will forward your requests to the web service is created. This class will implement the provided interface.
Hope this is more clear!
Joined: Mar 26, 2006
a class that will forward your requests to the web service is created
Ivan As i had mentioned in my very first message that i did not create any artifact using any tool and i was
able to access the web service with the same piece of client code mentioned in my first message.
So, what i understood from your last response is that proxy class implementing that SEI (interface) is created at runtime
and deleted by the run time environment , so we are not able to find those proxy classes.
please correct me if i am wrong.
Joined: Oct 04, 2006
Yep, I'd say you got it right! :-)
A proxy class implementing the interface you supply is created at runtime.
Take a look at the java.lang.reflect.Proxy class in the JavaSE API - this is probably the mechanism used to create the runtime proxy.