Tuesday, October 28, 2014

How to create WSDL in Eclipse


How to create WSDL in Eclipse

WSDL (Web Service Description Language) is one of the core part of the web service development. In the WSDL file we defines what are the operations going to performs, how to access the services and service url end point etc. 

In the below tutorial you able to learn that, how to create the WSDL file for simple string manipulation function.

Objective : Create a WSDL with using eclipse.

Scope : Create a WSDL in eclipse and validate which is serve welcome message as a service response.

Requirements : 
  • Eclipse Java EE IDE

Step 1 : Create a java project in eclipse and name it as "WSDL".

Step 2 : Select the "WSDL" project and create a new WSDL file as below.
 - Right click of "WSDL" project > New > Other 
 - The New Select a wizard will appear.
 - Select Web Service > WSDL and click "Next" button on the wizard.
 - You have to name the WSDL at this point. Just name it as "helloworld.wsdl".





 - From the following wizard screen, except the Target name space rest of the settings kept as it is. Further more details of the setting able to find here.



 - Finally click the finish button.

Step 3 : Change the address to "http://localhost:8181/webservice/services/helloworld/". 

In future we are going to generate a service and client based on the WSDL created in this tutorial. 

The default operation name changed to "newOperation" to "sayHello" and save it.

The WSDL source looks like below.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://localhost:8181/webservice/services/helloworld/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="helloworld" targetNamespace="http://localhost:8181/webservice/services/helloworld/">
  <wsdl:types>
    <xsd:schema targetNamespace="http://localhost:8181/webservice/services/helloworld/">
      <xsd:element name="sayHello">
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element name="name" type="xsd:string"/>
          </xsd:sequence>
        </xsd:complexType>
      </xsd:element>
      <xsd:element name="sayHelloResponse">
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element name="output" type="xsd:string"/>
          </xsd:sequence>
        </xsd:complexType>
      </xsd:element>
    </xsd:schema>
  </wsdl:types>
  <wsdl:message name="sayHelloRequest">
    <wsdl:part element="tns:sayHello" name="parameters"/>
  </wsdl:message>
  <wsdl:message name="sayHelloResponse">
    <wsdl:part element="tns:sayHelloResponse" name="parameters"/>
  </wsdl:message>
  <wsdl:portType name="helloworld">
    <wsdl:operation name="sayHello">
      <wsdl:input message="tns:sayHelloRequest"/>
      <wsdl:output message="tns:sayHelloResponse"/>
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="helloworldSOAP" type="tns:helloworld">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="sayHello">
      <soap:operation soapAction="http://localhost:8181/webservice/services/helloworld/sayHello"/>
      <wsdl:input>
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="helloworld">
    <wsdl:port binding="tns:helloworldSOAP" name="helloworldSOAP">
      <soap:address location="http://localhost:8181/webservice/services/helloworld/"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>


Step 4 : For validate the WSDL just right click on the WSDL source and Validate. If any errors occurs its pointed with red color.


No comments:

Post a Comment