This documentation is archived and is not being maintained.

Operation Class

Provides an abstract definition of an action supported by the XML Web service. This class cannot be inherited.

For a list of all members of this type, see Operation Members.


[Visual Basic]
NotInheritable Public Class Operation
   Inherits DocumentableItem
public sealed class Operation : DocumentableItem
public __gc __sealed class Operation : public DocumentableItem
public class Operation extends DocumentableItem

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.


The Operation class corresponds to the Web Services Description Language (WSDL) <operation> element enclosed by the <portType> element. For more information about WSDL, see the specification at


[Visual Basic, C#, C++] The following example demonstrates a typical use of the Operation class. The example takes a ServiceDescription that does not have a PortType that supports the HTTP POST protocol. It adds a PortType instance that supports POST, and writes out a new WSDL contract.

[Visual Basic] 
Imports System
Imports System.Web.Services.Description
Imports System.Collections
Imports System.Xml

Class MyOperationClass
   Public Shared Sub Main()
      Dim myDescription As ServiceDescription = ServiceDescription.Read("Operation_5_Input_VB.wsdl")
      ' Create a 'PortType' object.
      Dim myPortType As New PortType()
      myPortType.Name = "OperationServiceHttpPost"
      Dim myOperation As Operation = CreateOperation("AddNumbers", "s0:AddNumbersHttpPostIn", _
      ' Get the PortType of the Operation. 
      Dim myPort As PortType = myOperation.PortType
        Console.WriteLine( _
           "The port type of the operation is: " & myPort.Name)
      ' Add the 'PortType's to 'PortTypeCollection' of 'ServiceDescription'.
      ' Write the 'ServiceDescription' as a WSDL file.
      Console.WriteLine("WSDL file with name 'Operation_5_Output_VB.wsdl'" + _ 
                           "file created Successfully")
   End Sub 'Main
   Public Shared Function CreateOperation(myOperationName As String, myInputMesg As String, _
                                                         myOutputMesg As String) As Operation
      ' Create an Operation.
      Dim myOperation As New Operation()
      myOperation.Name = myOperationName
      Dim myInput As OperationMessage = _
         CType(New OperationInput(), OperationMessage)
      myInput.Message = New XmlQualifiedName(myInputMesg)
      Dim myOutput As OperationMessage = _
         CType(New OperationOutput(), OperationMessage)
      myOutput.Message = New XmlQualifiedName(myOutputMesg)

      ' Add messages to the OperationMessageCollection.
      Console.WriteLine("Operation name is: " & myOperation.Name)
      Return myOperation
   End Function 'CreateOperation 
End Class 'MyOperationClass 

using System;
using System.Web.Services.Description;
using System.Collections;
using System.Xml;

class MyOperationClass
   public static void Main()
      ServiceDescription myDescription = ServiceDescription.Read("Operation_5_Input_CS.wsdl");
      // Create a 'PortType' object.
      PortType myPortType = new PortType();
      myPortType.Name = "OperationServiceHttpPost";
      Operation myOperation = CreateOperation
      // Get the PortType of the Operation. 
      PortType myPort = myOperation.PortType;
         "The port type of the operation is: " + myPort.Name);
      // Add the 'PortType's to 'PortTypeCollection' of 'ServiceDescription'.
      // Write the 'ServiceDescription' as a WSDL file.
      Console.WriteLine("WSDL file with name 'Operation_5_Output_CS.wsdl' file created Successfully");
   public static Operation CreateOperation(string myOperationName,string myInputMesg,string myOutputMesg)
      // Create an Operation.
      Operation myOperation = new Operation();
      myOperation.Name = myOperationName;
      OperationMessage myInput = (OperationMessage)new OperationInput();
      myInput.Message =  new XmlQualifiedName(myInputMesg);
      OperationMessage myOutput = (OperationMessage)new OperationOutput();
      myOutput.Message = new XmlQualifiedName(myOutputMesg);

      // Add messages to the OperationMessageCollection.
      Console.WriteLine("Operation name is: " + myOperation.Name);     
      return myOperation;

#using <mscorlib.dll>
#using <System.Xml.dll>
#using <System.Web.Services.dll>
#using <System.dll>
using namespace System;
using namespace System::Web::Services::Description;
using namespace System::Collections;
using namespace System::Xml;

Operation* CreateOperation(String* myOperationName,String* myInputMesg,String* myOutputMesg)
   // Create an Operation.
   Operation* myOperation = new Operation();
   myOperation->Name = myOperationName;
   OperationMessage* myInput = dynamic_cast<OperationMessage*>(new OperationInput());
   myInput->Message =  new XmlQualifiedName(myInputMesg);
   OperationMessage* myOutput = dynamic_cast<OperationMessage*>(new OperationOutput());
   myOutput->Message = new XmlQualifiedName(myOutputMesg);

   // Add messages to the OperationMessageCollection.
   Console::WriteLine(S"Operation name is: {0}", myOperation->Name);     
   return myOperation;

int main()
   ServiceDescription* myDescription = ServiceDescription::Read(S"Operation_5_Input_CS.wsdl");
   // Create a 'PortType' object.
   PortType* myPortType = new PortType();
   myPortType->Name = S"OperationServiceHttpPost";
   Operation* myOperation = CreateOperation
   // Get the PortType of the Operation. 
   PortType* myPort = myOperation->PortType;
      S"The port type of the operation is: {0}", myPort->Name);
   // Add the 'PortType's to 'PortTypeCollection' of 'ServiceDescription'.

   // Write the 'ServiceDescription' as a WSDL file.
   Console::WriteLine(S"WSDL file with name 'Operation_5_Output_CS.wsdl' file created Successfully");

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Namespace: System.Web.Services.Description

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System.Web.Services (in System.Web.Services.dll)

See Also

Operation Members | System.Web.Services.Description Namespace | PortType