This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Web Services and the fly likes Use a singleton for javax.xml.ws.Service instance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Use a singleton for javax.xml.ws.Service instance" Watch "Use a singleton for javax.xml.ws.Service instance" New topic
Author

Use a singleton for javax.xml.ws.Service instance

Emilio Meadow
Greenhorn

Joined: Jul 20, 2009
Posts: 19
Hi everyone, I'm pretty new to WS and I need some help.
I have a jax-ws generated client for a ws. The easiest approach to call the client would be



But, rather then instantiate all the times the service class, I'm trying to understand if i can just put a single instance in a Singleton and use the same instance if Service to access the ws (calling each time the getPort method).
The code would look something like this:



Thanks in advance.

e


- we all get it in the end -
Toper Jean Michel
Greenhorn

Joined: Jul 10, 2012
Posts: 2
Hello,

About your question on Web Service, I don't know. But about the singleton I can tell you that it won't work because you're trying to instantiate a no static field in a static bloc.

Use instend of :



Regards
Emilio Meadow
Greenhorn

Joined: Jul 20, 2009
Posts: 19
I know I know..
I realize the small typo when I was already away from my pc.
Thanks anyway.

Back to the question, I've searched a lot and it seems that it's a very common question but unfortunately I couldn't find any definitive answer.
I think though that javax.xml.ws.Service seems to be made to be shared among many calls to the ws, in fact it has an enumeration of ports and a set of methods "getPort" that will retrive "compatible port" (from the javadoc).
Anyway I'm still looking for an answer..
Palak Mathur
Ranch Hand

Joined: Jan 29, 2007
Posts: 313

Emilio Meadow wrote:I know I know..
I realize the small typo when I was already away from my pc.
Thanks anyway.

Back to the question, I've searched a lot and it seems that it's a very common question but unfortunately I couldn't find any definitive answer.
I think though that javax.xml.ws.Service seems to be made to be shared among many calls to the ws, in fact it has an enumeration of ports and a set of methods "getPort" that will retrive "compatible port" (from the javadoc).
Anyway I'm still looking for an answer..


Did you try using the client?


Palak Mathur | My Blog | TechJaunt | What is JavaRanch? | List of All FAQs
Emilio Meadow
Greenhorn

Joined: Jul 20, 2009
Posts: 19
Hi Palak,
I'm sorry, what you mean by client? I use the .jar genereated by the wsimport tool. What else?
e
Palak Mathur
Ranch Hand

Joined: Jan 29, 2007
Posts: 313

Emilio Meadow wrote:Hi Palak,
I'm sorry, what you mean by client? I use the .jar genereated by the wsimport tool. What else?
e


You wrote the code with the singleton implementation or modified the code generated by the tool. Did you try to run that? Sorry, let me know if you are not able to understand my question. I will try to rephrase it again.
Emilio Meadow
Greenhorn

Joined: Jul 20, 2009
Posts: 19
Ok, I got you.
I used the classes generated by the tool to write my code, this means the class and the interface were generated by wsimport.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Use a singleton for javax.xml.ws.Service instance
 
Similar Threads
JAX-WS Authentication problem -javax.xml.ws.WebServiceException Response: '401: Unauthorized'
No getPort method in javax.xml.ws.Service
Spring MVC -- where does the model code go?
Jax-ws 2.2.1: creating clients for endpoints that are not in the WSDL
scjd questions