different components of WSDL

different components of WSDL

WSDL (Web Services Description Language) is an XML-based language used to describe web services and how to access them. WSDL documents are essential for specifying the functionalities of a web service, including its operations, messages, and how clients can interact with it. The main components of a WSDL document are:

different components of WSDL

  • 1.  Types : Defines the data types used by the web service, typically using XML Schema.
  • 2.  Messages : Describes the data being exchanged between the web service and the client. Each message consists of one or more parts.
  • 3.  PortType : Describes a set of operations supported by one or more endpoints. It’s the equivalent of a method signature in a programming language.
  • 4.  Binding : Specifies the protocol and data format for each port type. It defines how the operations are transmitted over the network.
  • 5.  Service : Specifies the endpoint (or address) where the service can be accessed.
  • 6.  Port : Defines an individual endpoint by specifying a single address for a binding.

Explanation in Java Example

To demonstrate the use of WSDL components in Java, we’ll create a simple SOAP web service and illustrate how these components fit into the WSDL file.

1. Creating the SOAP Web Service
java
import javax.jws.WebMethod;
import javax.jws.WebService;

@WebService
public interface HelloWorld {
    @WebMethod
    String sayHello(String name);
}

Service Implementation
java
import javax.jws.WebService;

@WebService(endpointInterface = "com.example.HelloWorld")
public class HelloWorldImpl implements HelloWorld {
    @Override
    public String sayHello(String name) {
        return "Hello, " + name + "!";
    }
}

2. Publishing the SOAP Web Service
java
import javax.xml.ws.Endpoint;

public class HelloWorldPublisher {
    public static void main(String[] args) {
        Endpoint.publish("http://localhost:8080/ws/hello", new HelloWorldImpl());
        System.out.println("Service is published!");
    }
}

3.  Accessing the WSDL File

Once the service is published, JAX-WS will automatically generate the WSDL file. You can access it by navigating to http://localhost:8080/ws/hello?wsdl in your web browser.

Breakdown of WSDL Components

Here’s how the WSDL file generated for the above service might look:

3. Accessing the WSDL File
xml
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
             xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
             xmlns:tns="http://example.com/"
             xmlns:xsd="http://www.w3.org/2001/XMLSchema"
             name="HelloWorldImplService"
             targetNamespace="http://example.com/">
    <!-- Types -->
    <types>
        <xsd:schema>
            <xsd:import namespace="http://example.com/" schemaLocation="http://localhost:8080/ws/hello?xsd=1"/>
        </xsd:schema>
    </types>

    <!-- Messages -->
    <message name="sayHelloRequest">
        <part name="parameters" element="tns:sayHello"/>
    </message>
    <message name="sayHelloResponse">
        <part name="parameters" element="tns:sayHelloResponse"/>
    </message>

    <!-- PortType -->
    <portType name="HelloWorld">
        <operation name="sayHello">
            <input message="tns:sayHelloRequest"/>
            <output message="tns:sayHelloResponse"/>
        </operation>
    </portType>

    <!-- Binding -->
    <binding name="HelloWorldImplPortBinding" type="tns:HelloWorld">
        <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
        <operation name="sayHello">
            <soap:operation soapAction=""/>
            <input>
                <soap:body use="literal"/>
            </input>
            <output>
                <soap:body use="literal"/>
            </output>
        </operation>
    </binding>

    <!-- Service -->
    <service name="HelloWorldImplService">
        <port name="HelloWorldImplPort" binding="tns:HelloWorldImplPortBinding">
            <soap:address location="http://localhost:8080/ws/hello"/>
        </port>
    </service>
</definitions>

Explanation

  • 1.  Types :
    • This section imports XML Schema definitions that describe the data types used by the service.
  • 2.  Messages :
    • sayHelloRequest and sayHelloResponse messages define the input and output data for the sayHello operation.
  • 3.  PortType :
    • The HelloWorld portType defines the sayHello operation, specifying the input and output messages.
  • 4.  Binding :
    • The HelloWorldImplPortBinding binding specifies that the operations will be transmitted over HTTP using SOAP.
  • 5.  Service :
    • The HelloWorldImplService service defines the endpoint where the service can be accessed. It uses the previously defined binding and specifies the address of the service.