25.2. Creating a Service Object
javax.xml.ws.Serviceclass represents the
wsdl:serviceelement which contains the definition of all of the endpoints that expose a service. As such, it provides methods that allow you to get endpoints, defined by
wsdl:portelements, that are proxies for making remote invocations on a service.
Serviceclass provides the abstractions that allow the client code to work with Java types as opposed to working with XML documents.
The create() methods
Serviceclass has two static
create()methods that can be used to create a new
Serviceobject. As shown in Example 25.1, “
create()Methods”, both of the
create()methods take the QName of the
Serviceobject will represent, and one takes a URI specifying the location of the WSDL contract.
public static Service create(URL wsdlLocation,
public static Service create(QName serviceName)
serviceNameparameter is a QName. The value of its namespace part is the target namespace of the service. The service's target namespace is specified in the targetNamespace property of the
@WebServiceannotation. The value of the QName's local part is the value of
nameattribute. You can determine this value in one of the following ways:
- It is specified in the serviceName property of the
- You append
Serviceto the value of the name property of the
- You append
Serviceto the name of the SEI.
ServiceObject” shows code for creating a
Serviceobject for the SEI shown in Example 24.7, “Fully Annotated SEI”.
Example 25.2. Creating a
ServiceObject” does the following:
- Builds the QName for the service using the targetNamespace property and the name property of the
- Calls the single parameter
create()method to create a new
Serviceobject.NoteUsing the single parameter
create()frees you from having any dependencies on accessing a WSDL contract.