An EJB or a servlet that wants to use Web Services (as a client) must declare a dependency on the Web Service with a service-ref element (same principle as for all *-ref elements).
The service-ref element declares a reference to a Web Service used by a J2EE component in the web, EJB, and client Deployment Descriptor.
The component uses a logical name called a service-ref-name to look up the service instance. Thus, any component that performs a lookup on a Web Service must declare a dependency (the service-ref element) in the standard deployment descriptor (web.xml application-client.xml, or ejb-jar.xml).
Example of service-ref:
<service-ref> <!-- (Optional) A Web Services description that can be used in administration tool. --> <description>Sample WebService Client</description> <!-- (Optional) The WebService reference name (used in Administration tools) --> <display-name>WebService Client 1</display-name> <!-- (Optional) An icon for this WebService. --> <icon> <!-- ... --> </icon> <!-- The logical name for the reference that is used in the client source code. It is recommended, but not required, that the name begin with 'services/' --> <service-ref-name>services/myService</service-ref-name> <!-- Defines the class name of the JAX-RPC Service interface that the client depends on. In most cases, the value will be javax.xml.rpc.Service, but a generated specific Service Interface class may be specified (requires WSDL knowledge and so on for the wsdl-file element). --> <service-interface>javax.xml.rpc.Service</service-interface> <!-- (Optional) Contains the location (relative to the root of the module) of the Web Service WSDL description. -needs to be in the wsdl directory -required if generated interface and sei are declared. --> <wsdl-file>WEB-INF/wsdl/stockQuote.wsdl</wsdl-file> <!-- (Optional) A file specifying the correlation of the WSDL definition to the interfaces (Service Endpoint Interface, Service Interface). -required if generated interface and sei (Service Endpoint Interface) are declared.--> <jaxrpc-mapping-file>WEB-INF/myMapping.xml</jaxrpc-mapping-file> <!-- (Optional) Declares the specific WSDL service element that is being referred to. It is not specified if no wsdl-file is declared or if WSDL contains only 1 service element. A service-qname is composed by a namespaceURI and a localpart. You must define it if more than 1 service is declared in the WSDL. --> <service-qname> <namespaceURI>http://beans.ws.objectweb.org</namespaceURI> <localpart>MyWSDLService</localpart> </service-qname> <!-- Declares a client dependency on the container to resolving a Service Endpoint Interface to a WSDL port. It optionally associates the Service Endpoint Interface with a particular port-component. --> <port-component-ref> <service-endpoint-interface> org.objectweb.ws.beans.ssbendpoint.MyService </service-endpoint-interface> <!-- Define a link to a port component declared in another unit of the application --> <port-component-link> ejb_module.jar#PortComponentName </port-component-link> </port-component-ref> <!--A list of Handler to use for this service-ref --> <handler> <!-- Must be unique within the module. --> <handler-name>MyHandler</handler-name> <handler-class>org.objectweb.ws.handlers.myHandler</handler-class> <!-- A list of init-param (couple name/value) for Handler initialization --> <init-param> <param-name>param_1</param-name> <param-value>value_1</param-value> </init-param> <!-- A list of QName specifying the SOAP Headers the handler will work on. -namespace and locapart values must be found inside the WSDL. --> <soap-header> <namespaceURI>http://ws.objectweb.org</namespaceURI> <localpart>MyWSDLHeader</localpart> </soap-header> <!-- A list of SOAP actor definition that the Handler will play as a role. A soap-role is a namespace URI. --> <soap-role>http://actor.soap.objectweb.org</soap-role> <!-- A list of port-name element defines the WSDL port-name that a handler should be associated with. If no port-name is specified, the handler is assumed to be associated with all ports of the service-ref. --> <port-name>myWSDLPort</port-name> </handler> </service-ref> |
A jonas-service-ref must be specified for each service-ref declared in the standard Deployment Descriptor. The jonas-service-ref adds JOnAS-specific (and Web Service engine-specific) information to service-ref elements.
Example of jonas-service-ref:
<jonas-service-ref> <!-- Define the service-ref contained in the component deployment descriptor (web.xml, ejb-jar.xml, or application-client.xml) used as a key to associate a service-ref to its corresponding jonas-service-ref--> <service-ref-name>services/myService</service-ref-name> <!-- Define the physical name of the resource. --> <jndi-name>webservice_1</jndi-name> <!-- A list of init-param used for specific configuration of the service --> <jonas-init-param> <param-name>param</param-name> <param-value>name</param-value> </jonas-init-param> </jonas-service-ref> |