This documentation is archived and is not being maintained.

OperationCollection Class

Represents a collection of instances of the Operation class. This class cannot be inherited.

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

public sealed class OperationCollection : ServiceDescriptionBaseCollection

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 http://www.w3.org/TR/wsdl/.

The following example demonstrates the use of the properties and methods exposed by the OperationCollection class.

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

class MyOperationCollectionSample
{
   public static void Main()
   {
      try
      {
         // Read the 'MathService_Input_cs.wsdl' file.
         ServiceDescription myDescription = 
                     ServiceDescription.Read("MathService_Input_cs.wsdl");
         PortTypeCollection myPortTypeCollection =myDescription.PortTypes;
         // Get the 'OperationCollection' for 'SOAP' protocol.
         OperationCollection myOperationCollection = 
                                       myPortTypeCollection[0].Operations;
         Operation myOperation = new Operation();
         myOperation.Name = "Add";
         OperationMessage myOperationMessageInput = 
                                  (OperationMessage) new OperationInput();
         myOperationMessageInput.Message = new XmlQualifiedName
                              ("AddSoapIn",myDescription.TargetNamespace);
         OperationMessage myOperationMessageOutput = 
                                 (OperationMessage) new OperationOutput();
         myOperationMessageOutput.Message = new XmlQualifiedName(
                              "AddSoapOut",myDescription.TargetNamespace);
         myOperation.Messages.Add(myOperationMessageInput);
         myOperation.Messages.Add(myOperationMessageOutput);
         myOperationCollection.Add(myOperation);

         if(myOperationCollection.Contains(myOperation) == true)
         {
            Console.WriteLine("The index of the added 'myOperation' " +
                              "operation is : " +
                              myOperationCollection.IndexOf(myOperation));
         }

         myOperationCollection.Remove(myOperation);
         // Insert the 'myOpearation' operation at the index '0'.
         myOperationCollection.Insert(0, myOperation);
         Console.WriteLine("The operation at index '0' is : " +
                           myOperationCollection[0].Name);

         Operation[] myOperationArray = new Operation[
                                             myOperationCollection.Count];
         myOperationCollection.CopyTo(myOperationArray, 0);
         Console.WriteLine("The operation(s) in the collection are :");
         for(int i = 0; i < myOperationCollection.Count; i++)
         {
            Console.WriteLine(" " + myOperationArray[i].Name);
         }

         myDescription.Write("MathService_New_cs.wsdl");
      }
      catch(Exception e)
      {
         Console.WriteLine("Exception caught!!!");
         Console.WriteLine("Source : " + e.Source);
         Console.WriteLine("Message : " + e.Message);
      }
   }
}
#using <mscorlib.dll>
#using <System.Xml.dll>
#using <System.Web.Services.dll>
using namespace System;
using namespace System::Web::Services;
using namespace System::Xml;
using namespace System::Web::Services::Description;

int main()
{
   try
   {
      // Read the 'MathService_Input_cs.wsdl' file.
      ServiceDescription* myDescription =
         ServiceDescription::Read(S"MathService_Input_cs.wsdl");
      PortTypeCollection* myPortTypeCollection =myDescription->PortTypes;
      // Get the 'OperationCollection' for 'SOAP' protocol.
      OperationCollection* myOperationCollection =
         myPortTypeCollection->Item[0]->Operations;
      Operation* myOperation = new Operation();
      myOperation->Name = S"Add";
      OperationMessage* myOperationMessageInput =
         dynamic_cast<OperationMessage*> (new OperationInput());
      myOperationMessageInput->Message = new XmlQualifiedName
         (S"AddSoapIn",myDescription->TargetNamespace);
      OperationMessage* myOperationMessageOutput =
         dynamic_cast<OperationMessage*> (new OperationOutput());
      myOperationMessageOutput->Message = new XmlQualifiedName(
         S"AddSoapOut",myDescription->TargetNamespace);
      myOperation->Messages->Add(myOperationMessageInput);
      myOperation->Messages->Add(myOperationMessageOutput);
      myOperationCollection->Add(myOperation);

      if(myOperationCollection->Contains(myOperation) == true)
      {
         Console::WriteLine(S"The index of the added 'myOperation' operation is : {0}",
            __box(myOperationCollection->IndexOf(myOperation)));
      }

      myOperationCollection->Remove(myOperation);
      // Insert the 'myOpearation' operation at the index '0'.
      myOperationCollection->Insert(0, myOperation);
      Console::WriteLine(S"The operation at index '0' is : {0}", myOperationCollection->Item[0]->Name);

      Operation* myOperationArray[] = new Operation*[myOperationCollection->Count];
      myOperationCollection->CopyTo(myOperationArray, 0);
      Console::WriteLine(S"The operation(s) in the collection are :");
      for(int i = 0; i < myOperationCollection->Count; i++)
      {
         Console::WriteLine(S" {0}", myOperationArray[i]->Name);
      }

      myDescription->Write(S"MathService_New_cs.wsdl");
   }
   catch(Exception* e)
   {
      Console::WriteLine(S"Exception caught!!!");
      Console::WriteLine(S"Source : {0}", e->Source);
      Console::WriteLine(S"Message : {0}", e->Message);
   }
}

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

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Show: