Thursday, 26 January 2017

Create a WSDL from XSD

Sometimes it is required to create service interface(WSDL) from the schema(XSD) file.

This post shows you how to create interface- WSDL from the given XSD using Jdeveloper 12c.

Let's go step by step.

1) Suppose you have a Application and a project in the JDeveloper.

2) Right click on the project and create a schema file


 3) Create the XSD structure like below


<?xml version="1.0" encoding="windows-1252" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.example.org"
            targetNamespace="http://www.example.org" elementFormDefault="qualified">
  <xsd:element name="request">
    <xsd:annotation>
      <xsd:documentation>A sample element</xsd:documentation>
    </xsd:annotation>
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="id" type="xsd:integer"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
  <xsd:element name="response">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="name" type="xsd:string"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
  <xsd:element name="fault">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="error" type="xsd:string"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
</xsd:schema>

4) Let's create a WSDL document. Right click on the project-> New -> WSDL Document


5) Arrange the schema and WSDL editor windows in a vertical split arrangement like as shown below. This can be achieved by dragging the test.xsd tab below


6) Let's create the WSDL document. Drag and Drop the request element from the XSD to the Port Types window. A popup will get open. Rename the Port Type Name as shown below


7) WSDL will look like


8) Here we can see, input and ouput refer to both request element. To correct this, select the output node from the Port Types window and drag and drop response element from the schema onto the output element


9) Add a fault node in the Port Types. To do so, first add the Message part, Drag and Drop the fault element from the schema on the Message window and rename Message name as EmpFault





10) Right click on the output node, Insert After Output -> fault. 


11) Enter name as EmpFault and select tns:EmpFault from the message drop down



12) After the above steps, your WSDL document look like this


13) Now Drag and Drop EmpDemo node from Port Types window to Binding / Partner Links Type window and click OK



Your WSDL look like this



14) Now drag and drop the EmpDempSOAP1Binding node to the Services Wndow. After this step WSDL document look like this.


WSDL has been completed. Now validate the WSDL to see the WSDL we have created is valid or not. Right Click on the test.wsdl and click Validate WSDL





You can use this WSDL to create the services.

It's done.

2 comments:

  1. Thank you Ankur this post. But we can also create WSDL from XSD using WSDL builder very easily in 12c Jdeveloper. Regards Sanddy

    ReplyDelete