Open In App

WSDL <portType> Element

Last Updated : 17 Oct, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The <portType> element defines an interface for the web service used by the user or client. It contains a set of operations that a web service supports.

For each operation, it defines the input and output messages, which in turn helps the client by providing them with a contract that specifies what operations are available for them and based on them the client decides what data they should send or receive.

Syntax:

<portType name="PortTypeName">
  <!-- Operations are added here -->
</portType>

Patterns of Operation:

WSDL support Four basic pattern of operations which are described below with example code:

1. Simple One-Way Operation

It is used when the user or client wants to initiate an action on the server but does not want any response. The operation does not take any input parameters and returns no output.

XML




<!--portType name-->
<portType name="SimpleOneWayService">
  <operation name="TriggerAction">         
    <!--Triggers the expected Action-->
    <input message="tns:TriggerActionRequest"/>   
  </operation>
</portType>


2. Simple Request-Response Operation

It is similar to Single One Way operation but in this, the user or client sends a request to the server and in turn, receives a response.

XML




<!--portType name-->
<portType name="SimpleRequestResponseService"
  <operation name="GetData">
    <input message="tns:GetDataRequest"/>
    <output message="tns:GetDataResponse"/>
  </operation>
</portType>


3. Multiple Operations

Multiple operations within the same <portType> element to specify various actions. We have various example for multiple operation in more detail for this operation.

XML




<!--portType name-->
<portType name="MultiOperationService">    
  <operation name="Operation1">
    <input message="tns:Operation1Request"/>
    <output message="tns:Operation1Response"/>
  </operation>
  <operation name="Operation2">
    <input message="tns:Operation2Request"/>
    <output message="tns:Operation2Response"/>
  </operation>
</portType>


Example: Here we will see <portType> element with one <operation>

XML




<!--portType name-->
<portType name="Calculator">                 
  <operation name="Multiply">
    <!--input message-->
    <input message="tns:AddInputMessage"/>       
    <!--output message-->
    <output message="tns:AddOutputMessage"/>     
  </operation>
</portType>


  • <portType name=”Calculator”> Describes a portType named Calculator, which provides an interface to the user to perform the operations
  • <operation_name=”Multiply”> defines the operation to be performed
  • <input message=”tns:AddInputMessage”/> specifies that the “Multiply” operation needs an input message
  • <output message=”tns:AddOutputMessage”/> specifies that the “Multiply” operation produces an output message

Example: Here we will see <portType> element with two <operation>

This WSDL port type represents a contract for a calculator web service with two available operations: “Add” and “Subtract.”

XML




<!--portType name-->
<portType name="Calculator">      
  <operation name="Add">
    <!--input message-->
    <input message="tns:AddInputMessage"/>   
    <!--output message-->
    <output message="tns:AddOutputMessage"/>  
  </operation>
    
  <operation name="Subtract">
    <!--input message-->
    <input message="tns:SubtractInputMessage"/>   
    <!--output message-->
    <output message="tns:SubtractOutputMessage"/>  
  </operation>
</portType>


4. Operations with Complex Input and Output

Complex input and output types can also be defined in <portType> definition.

XML




<!--portType name-->
<portType name="ComplexIOService">   
  <operation name="ProcessData">
    <input message="tns:ProcessDataRequest"/>
    <output message="tns:ProcessDataResponse"/>
  </operation>
</portType>




Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads