aspose file tools*
The moose likes Web Services Certification (SCDJWS/OCEJWSD) and the fly likes @WebServiceRef(type=...) vs @WebServiceRef Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Services Certification (SCDJWS/OCEJWSD)
Bookmark "@WebServiceRef(type=...) vs @WebServiceRef " Watch "@WebServiceRef(type=...) vs @WebServiceRef " New topic
Author

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

Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 813
    
    1
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

Joined: Jul 29, 2012
Posts: 813
    
    1
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
Bartender

Joined: Apr 07, 2010
Posts: 1733
    
  25

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

Joined: Jul 29, 2012
Posts: 813
    
    1
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
Bartender

Joined: Apr 07, 2010
Posts: 1733
    
  25

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
 
 
subject: @WebServiceRef(type=...) vs @WebServiceRef