Creating a WSDL file using Eclipse
- April 26, 2022
Web Service Descriptive Language (WSDL) is an XML-based definition language used for describing the functionality of a SOAP-based web service. WSDL describes how to access a web service and what operations it will perform.
Like RAML is for for REST APIs, WSDL is for SOAP APIs. While most people know how to create a RAML file using Anypoint Platform, many seem to struggle when it comes to creating a WSDL file from scratch. So, in this tech article, we’ll learn how to create a WSDL file using Eclipse IDE.
Creating a skeleton WSDL file
Let’s create a new project in your Eclipse IDE. Go to File → New → Project → Java EE → Utility Project. The option of creating a WSDL file is available in any type of Java Enterprise Edition project. Provide a project name and click Finish.
To create the file, right-click on the project and go to New → Other → Web Services → WSDL file and click Next. Name the WSDL file and click Next. In this article, we’ll create Employee.wsdl.
On the next page, you’ll have the option to change the Target namespace, Prefix, SOAP Binding and so on. By default, the Target namespace will be www.example.org, but you can change. In this case, change it to http://www.apisero.com/Employee/. Then change the prefix to ‘emp’ and keep the binding default — document literal — and click Finish. It will create a skeleton WSDL.
There are two tabs at the bottom of the editor: Design and Source. Source is the XML editor and Design is the graphical editor.
You’ll see that a basic skeleton WSDL has been created by default. Now, let’s go to the Design and use the drag-and-drop format to edit the skeleton WSDL.
Adding operations
Like methods in RAML/REST, WSDL/SOAP has operations. You’ll see that an operation named NewOperation has been created by default. Double-click on it and change the name to something more meaningful. In this case, change it to GetEmployee.
Next, you need to define the input parameters required to call this operation and the output parameters or response expected from this operation. To add the input parameters, click the arrow next to it. The inline schema will open in a separate tab. By default, the input parameter is in and the type is string. In this case, change the name of the parameter to EmployeeId.
Go back to the main WSDL and click the arrow next to the output parameter. You’ll see that by default the parameter is out and type is string. In this case, change it to Name. To add a new element, right-click on (GetEmployeeResponseType) and go to Add Element. Add Email with type string, Phone with type integer and Designation with type string.
Adding complex types
Let’s add one more element to the response (Address). It will be a complexType, not a simpleType. A simpleType element contains only text. It cannot have attributes or child elements. A complexType element can contain text, child elements and attributes. Select the type as New and click OK.
To edit the Address type, on the right-hand side go to Outline and expand Types. Double-click on AddressType and add elements to it.
Reusing complex types
Let’s create one more complexType with the name EmployeeType. Go to Types, right-click and Add Complex Type. Add elements to EmployeeType.
Go back to GetEmployeeResponse and delete all the elements added previously. Then add one element and refer to its type as the newly created EmployeeType. To do that, select Browse from the drop-down list of type and then select EmployeeType.
Now let’s create another operation, called Add Employee. Go to the main WSDL, right-click on Employee and click Add Operation. Add an input parameter to the Add Employee operation. For type, again select the EmployeeType.
So, the ComplexType — EmployeeType is being used as an input type for the AddEmployee and as an output type for the GetEmployee operations.
Now add the output parameter for the AddEmployee operation: ResponseMessage.
Making elements optional/required
By default, all elements are required; that is, maxOccurs=“1″ and minOccurs=“1.″ To make an element optional, right-click on it, go to Set Multiplicity and select 0..1 (Optional). In this case, make the Designation optional.
Importing XSD into WSDL
So far, we’ve defined all the elements inside the WSDL itself. Ideally, we should create separate XSDs for the inputs and outputs of different operations, and then import those XSDs inside the WSDL. Here’s how to do the import.
Start by creating an XSD file inside the project or pasting one in if you’ve already created one. This step isn’t required if your XSDs are uploaded on the server.
Next, go to Outline, right-click on Imports and then click Add import. Go to Properties and provide the location of the XSD file.
You can also do it using the XML editor:
<wsdl:types>
<xsd:schema>
<xsd:import namespace=”http://www.apisero.com/Employee/” schemaLocation=”EmployeeInput.xsd”/>
</xsd:schema>
</wsdl:types>
Or if the XSD is uploaded on the server:
<wsdl:types>
<xsd:schema>
<xsd:import namespace=”http://www.apisero.com/Employee/” schemaLocation=”http://www.apisero.com/Employee/schemas/EmployeeInput.xsd”/>
</xsd:schema>
</wsdl:types>
Conclusion
Go to the source tab and you’ll see the entire created WSDL. In the Outline section, you’ll see all the different defined elements.
Remember, this is an abstract WSDL that’s used on the server side. You can import this WSDL into MuleSoft Anypoint Studio (or other similar tools) and do the actual implementation of the SOAP API. Then you can expose the API and share the concrete WSDL for consumption with the API.
— By Biswajit Kalita