Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Emilio Meadow
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Toper Jean Michel
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 342
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Emilio Meadow
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 342
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic