Inspecting WSDL

We are done with implementing our web service. As you can see, JAX-WS really makes it very easy to develop web services. Let's now inspect the WSDL of our web service. Configure Tomcat in Eclipse as described in Installing Tomcat section of Chapter 1, Introducing JEE and Eclipse and in the Configuring Tomcat in Eclipse section of Chapter 2, Creating a Simple JEE Web Application. To deploy the web application, right-click on the configured Tomcat server in Servers view and select the Add and Remove option:

Figure 9.9: Add a project to Tomcat

Add the project and click Finish.

Start the Tomcat server by right-clicking on the configured server in the Servers view and selecting Start.

To inspect the WSDL of our web service, browse to http://localhost:8080/CourseMgmtWSProject/courseService?wsdl (assuming that Tomcat is running on port 8080). The following WSDL should be generated (see the description following Figure 9.6 in the WSDL section to understand the structure of the WSDL generated here):

<definitions 
  xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" 
  xmlns:wsp="http://www.w3.org/ns/ws-policy" 
xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://soap.ws.eclipse.jee.packt/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/"
targetNamespace="http://soap.ws.eclipse.jee.packt/" name="CourseManagementServiceService"> <types> <xsd:schema> <xsd:import namespace="http://soap.ws.eclipse.jee.packt/" schemaLocation="http://localhost:8080/CourseMgmtWSProject/courseService?xsd=1" /> </xsd:schema> </types> <message name="getCourses"> <part name="parameters" element="tns:getCourses" /> </message> <message name="getCoursesResponse"> <part name="parameters" element="tns:getCoursesResponse" /> </message> <message name="getCourse"> <part name="parameters" element="tns:getCourse" /> </message> <message name="getCourseResponse"> <part name="parameters" element="tns:getCourseResponse" /> </message> <portType name="CourseManagementService"> <operation name="getCourses"> <input wsam:Action="http://soap.ws.eclipse.jee.packt/CourseManagementService/getCoursesRequest" message="tns:getCourses" /> <output wsam:Action="http://soap.ws.eclipse.jee.packt/CourseManagementService/getCoursesResponse" message="tns:getCoursesResponse" /> </operation> <operation name="getCourse"> <input wsam:Action="http://soap.ws.eclipse.jee.packt/CourseManagementService/getCourseRequest" message="tns:getCourse" /> <output wsam:Action="http://soap.ws.eclipse.jee.packt/CourseManagementService/getCourseResponse" message="tns:getCourseResponse" /> </operation> </portType> <binding name="CourseManagementServicePortBinding"
type="tns:CourseManagementService"> <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" /> <operation name="getCourses"> <soap:operation soapAction="" /> <input> <soap:body use="literal" /> </input> <output> <soap:body use="literal" /> </output> </operation> <operation name="getCourse"> <soap:operation soapAction="" /> <input> <soap:body use="literal" /> </input> <output> <soap:body use="literal" /> </output> </operation> </binding> <service name="CourseManagementServiceService"> <port name="CourseManagementServicePort"
binding="tns:CourseManagementServicePortBinding"> <soap:address location="http://localhost:8080/CourseMgmtWSProject/courseService"
/> </port> </service> </definitions>

Notice that the schema (see the definitions of the /types/xsd:schemas element) for this web service is imported in the previous WSDL. You can see the schema generated at http://localhost:8080/CourseMgmtWSProject/courseService?xsd=1:

<xs:schema xmlns:tns="http://soap.ws.eclipse.jee.packt/" 
  xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0" 
  targetNamespace="http://soap.ws.eclipse.jee.packt/"> 
 
  <xs:element name="getCourse" type="tns:getCourse" /> 
  <xs:element name="getCourseResponse" 
type="tns:getCourseResponse" /> <xs:element name="getCourses" type="tns:getCourses" /> <xs:element name="getCoursesResponse"
type="tns:getCoursesResponse" /> <xs:complexType name="getCourses"> <xs:sequence /> </xs:complexType> <xs:complexType name="getCoursesResponse"> <xs:sequence> <xs:element name="return" type="tns:course" minOccurs="0" maxOccurs="unbounded" /> </xs:sequence> </xs:complexType> <xs:complexType name="course"> <xs:sequence> <xs:element name="credits" type="xs:int" /> <xs:element name="id" type="xs:int" /> <xs:element name="name" type="xs:string" minOccurs="0" /> </xs:sequence> </xs:complexType> <xs:complexType name="getCourse"> <xs:sequence> <xs:element name="arg0" type="xs:int" /> </xs:sequence> </xs:complexType> <xs:complexType name="getCourseResponse"> <xs:sequence> <xs:element name="return" type="tns:course" minOccurs="0" /> </xs:sequence> </xs:complexType> </xs:schema>

The schema document defines data types for the getCourse and getCourses methods and their responses (getCoursesResponse and getCourseResponse), and also for the Course class. It also declares members of the Course data type (id, credits, and name). Notice that the getCourse data type has one child element (which is an argument to the call to the getCourse method in CourseManagementService) called arg0, which is actually the course ID of the int type. Further, notice the definition of getCoursesResponse. In our implementation class, getCourses returns List<Course>, which is translated in WSDL (or types in WSDL) as a sequence of course types.

The following four messages are defined in the previous WSDL: getCourses, getCoursesResponse, getCourse, and getCourseResponse. Each message contains a part element that refers to data types declared in types (or schema).

The PortType name is the same as the web service implementation class called CourseManagementService and operations of the port are the same as public methods of the class. The input and output of each operation refers to messages already defined in the WSDL.

The binding defines the network transport type, which in this case is HTTP, and the style of message in the SOAP body, which is of the document type. We have not defined any message type in our web service implementation, but the JAX-WS reference implementation (Glassfish Metro) has set a default message type to document. Binding also defines the message encoding type for the input and output messages of each operation.

Finally, the Service element specifies the location of the port, which is the URL that we access to invoke the web service.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.189.199