A WSDL describes a set of business operations. The WSDL HelloWSService.wsdl
for the sample web service defines an operation "hello" that takes an input parameter and returns a response. The HelloWSService.wsdl
used in this chapter has elements that are discussed in the following table:
Element |
Description |
---|---|
message |
Describes input and output parameters and return values. |
types |
Describes the schema ( |
portType |
Describes the operations and associated messages. Defines abstract operations. |
binding |
Binding |
service |
Service |
port |
Port and the binding used for service access. |
To learn more about WSDL refer to http://www.w3.org/TR/wsdl. The HelloWSService.wsdl
is listed as follows:
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://hellows/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="HelloWSService" targetNamespace="http://hellows/"> <types> <xsd:schema> <xsd:import namespace="http://hellows/" schemaLocation="HelloWSService_metadata1.xsd"> </xsd:import> </xsd:schema> </types> <message name="hello"> <part element="tns:hello" name="parameters"></part> </message> <message name="helloResponse"> <part element="tns:helloResponse" name="parameters"></part> </message> <portType name="HelloWS"> <operation name="hello"> <input message="tns:hello"></input> <output message="tns:helloResponse"></output> </operation> </portType> <binding name="HelloWSPortBinding" type="tns:HelloWS"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"> </soap:binding> <operation name="hello"> <soap:operation soapAction=""></soap:operation> <input> <soap:body use="literal"></soap:body> </input> <output> <soap:body use="literal"></soap:body> </output> </operation> </binding> <service name="HelloWSService"> <port binding="tns:HelloWSPortBinding" name="HelloWSPort"> <soap:address location="http://localhost:8080/clientjar/hellows?wsdl"> </soap:address> </port> </service> </definitions>
The XML types used in the input and output messages are described in the schema for the web service, HelloWSService_metadata1.xsd
. The tns
namespace prefix defines the http://hellows/
namespace, which is the targetNamespace
of the schema. The schema has elements hello
and helloResponse
. The hello
element is of type tns:hello
, which defines an element arg0
for the input message parameter(s). The helloReponse
element is of type tns:helloResponse
, which defines the return value. The schema for the element is listed as follows:
<xs:schema xmlns:tns="http://hellows/" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://hellows/" version="1.0"> <xs:element name="hello" type="tns:hello"></xs:element> <xs:element name="helloResponse" type="tns:helloResponse"></xs:element> <xs:complexType name="hello"> <xs:sequence> <xs:element minOccurs="0" name="arg0" type="xs:string"></xs:element> </xs:sequence> </xs:complexType> <xs:complexType name="helloResponse"> <xs:sequence> <xs:element minOccurs="0" name="return" type="xs:string"></xs:element> </xs:sequence> </xs:complexType> </xs:schema>
Create a directory config
in the NetBeans project root directory HelloWS
and copy the WSDL and schema to the directory. When packaging the web service, the WSDL and the schema should be packaged in the WEB-INF/wsdl
folder.