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.
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.
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?
@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.
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.
Joined: Jul 29, 2012
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.