Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

@WebServiceRef(type=...) vs @WebServiceRef

 
Himai Minh
Ranch Hand
Posts: 1361
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why sometimes, we inject a service reference like this:
@WebServiceRef
private CatalogService catalogService ; //where CatalogService is a Service

or
@WebServiceRef (type=Catalog.class) //where Catalog is SEI
private CatalogService catalogService;

?

What is the different between them? Why sometimes we need type parameter and sometimes we don't need the type parameter?
 
Himai Minh
Ranch Hand
Posts: 1361
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let me rephrase my question. Actually, I want to ask what is the purpose to use type parameter for @WebServiceRef (type=...)? I read Ivan's note and Java SOA Cookbook, but I still don't understand why.
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2536
113
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you read the JAX-WS 2.x spec on this topic?
There are two uses to the WebServiceRef annotation:
1. To define a reference whose type is a generated service class. In this case, the type and value element will both refer to the generated service class type. Moreover, if the reference type can be inferred by the field/method declaration the annotation is applied to, the type and value elements MAY have the default value (Object.class, that is). If the type cannot be inferred, then at least the type element MUST be present with a non-default value.
2. To define a reference whose type is a SEI. In this case, the type element MAY be present with its default value if the type of the reference can be inferred from the annotated field/method declaration, but the value element MUST always be present and refer to a generated service class type (a subtypeof javax.xml.ws.Service).


Regards,
Frits
 
Himai Minh
Ranch Hand
Posts: 1361
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. I read these two definition from Java SOA Cookbook.
What is meant by if "type is not inferred"?
I can use MZ's notes' example:

@WebServiceRef (type =Catalog.class) //where Catalog is the SEI
private CatalogService service ; //where CatalogService is the generated Service

or

@WebServiceRef
private CatalogService service

What is the difference between these two examples?
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2536
113
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no difference between those examples: the type of the reference (i.e. CatalogService) can be inferred from the instance variable "service" (which is of type CatalogService). The type parameter can be left out.

An example where the type cannot be inferred (because there is no instance variable):

Regards,
Frits
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic