aspose file tools*
The moose likes Web Services Certification (SCDJWS/OCEJWSD) and the fly likes Difference between @WebService and @WebServiceProvider annotation? 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 "Difference between @WebService and @WebServiceProvider annotation?" Watch "Difference between @WebService and @WebServiceProvider annotation?" New topic
Author

Difference between @WebService and @WebServiceProvider annotation?

Mahabub Ali Mohammad
Greenhorn

Joined: Oct 30, 2008
Posts: 3
Hi All,

Can anyone explain me the difference between annotating a java service with @WebService and @WebServiceProvider?

Thanks in Advance
-Mahabub Ali Mohammad.
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
The annotation WebServiceProvider is used in endpoint classes implementing the javax.xml.ws.Provider<T> to associate the class with a <wsdl:service> element and a <wsdl:port> element in specified WSDL document. Such an endpoint works directly with (SOAP) messages or (SOAP) message payloads.
Note that the Provider<T> interface only has one single method, which in an implementing class will provide all the different messages received by the endpoint, while a class annotated with the WebService has one method for each kind of message the endpoint class can receive.
A class can either be annotated with the WebService or the WebServiceProvider annotation, but not both.

My free books and tutorials: http://www.slideshare.net/krizsan
Mahabub Ali Mohammad
Greenhorn

Joined: Oct 30, 2008
Posts: 3
Thanks Navi

Regards,
Mahabub Ali Mohammad.
anas alsarairah
Greenhorn

Joined: Sep 27, 2007
Posts: 28
hello

do you mean that the application server wont generate a WSDL file for web services annonated using @WebServiceProvider ?

thanks
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
anas alsarairah wrote:
do you mean that the application server wont generate a WSDL file for web services annonated using @WebServiceProvider ?

Correct - there is no way the application server knows what operations etc are supported by a web service annotated with @WebServiceProvider.
You may, however, supply an existing WSDL.
Best wishes!
Arnab Ban
Greenhorn

Joined: Aug 10, 2012
Posts: 2
Ivan Krizsan wrote:
Correct - there is no way the application server knows what operations etc are supported by a web service annotated with @WebServiceProvider.
You may, however, supply an existing WSDL.
Best wishes!


In another words, it is impossible to do bottom-up service development using @WebServiceProvider annotation? Please correct if wrong; if yes then how to consume the service?
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2615
    
    9

@Ivan is it correct to say that @WebService annotation is for "SOAP" service and @WebServiceProvider annotation for "REST" service?

Or @WebServiceProvider service can also be for SOAP service?


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5 OCPBCD5
Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 812
    
    1
@WebServiceProvider is used for XML based web services, not necessarily SOAP based web service.
With it, developers will need to parse the XML request or response using the XML parsers.
With it, no WSDL is generated. But with @WebService, a wsdl is generated.

If the service is annotated with @WebServiceProvider is implemented RESTfully (with Create, Update, Delete, Get methods), then it is a REST service.


Detail is given in Java Web Service Up and Running.
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2615
    
    9

Thanks Himai
Abhay Agarwal
Ranch Hand

Joined: Feb 29, 2008
Posts: 1220
    
    1

WebServiceProvider allows us to implement Web Services without Stub and WSDL.
WebServiceProvider are suitable for dynamically sending and recieving any SOAP message.
WebServiceProvider accepts an object marshalled by the JAX-WS engine as it is, and therefore for developing Web services , you must directly acquire values from XMLs that configure SOAP messages using APIs , and then assemble the XMLs.
Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 812
    
    1
One more exam watch, you may need to use SAAJ API to create an XML request or Soap attachment when the web service is @WebServiceProvider.
You may see one question on this. You have to know SAAJ.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Difference between @WebService and @WebServiceProvider annotation?