Export (0) Print
Expand All

OperationCollection Class

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

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

System.Object
   System.Collections.CollectionBase
      System.Web.Services.Description.ServiceDescriptionBaseCollection
         System.Web.Services.Description.OperationCollection

[Visual Basic]
NotInheritable Public Class OperationCollection
   Inherits ServiceDescriptionBaseCollection
[C#]
public sealed class OperationCollection :
   ServiceDescriptionBaseCollection
[C++]
public __gc __sealed class OperationCollection : public
   ServiceDescriptionBaseCollection
[JScript]
public class OperationCollection extends
   ServiceDescriptionBaseCollection

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.

Remarks

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/.

Example

[Visual Basic, C#, C++] The following example demonstrates the use of the properties and methods exposed by the OperationCollection class.

[Visual Basic] 
Option Strict On
Imports System
Imports System.Web.Services
Imports System.Xml
Imports System.Web.Services.Description

Class MyOperationCollectionSample
   Public Shared Sub Main()
      Try
         ' Read the 'MathService_Input_vb.wsdl' file.
         Dim myDescription As ServiceDescription = _
                        ServiceDescription.Read("MathService_Input_vb.wsdl")
         Dim myPortTypeCollection As PortTypeCollection = _
                                                   myDescription.PortTypes
         ' Get the 'OperationCollection' for 'SOAP' protocol.
         Dim myOperationCollection As OperationCollection = _
                                         myPortTypeCollection(0).Operations
         Dim myOperation As New Operation()
         myOperation.Name = "Add"
         Dim myOperationMessageInput As OperationMessage = _
                              CType(New OperationInput(), OperationMessage)
         myOperationMessageInput.Message = New XmlQualifiedName _
                              ("AddSoapIn", myDescription.TargetNamespace)
         Dim myOperationMessageOutput As OperationMessage = _
                              CType(New OperationOutput(), OperationMessage)
         myOperationMessageOutput.Message = New XmlQualifiedName _
                              ("AddSoapOut", myDescription.TargetNamespace)
         myOperation.Messages.Add(myOperationMessageInput)
         myOperation.Messages.Add(myOperationMessageOutput)
         myOperationCollection.Add(myOperation)

         If myOperationCollection.Contains(myOperation) = True Then
            Console.WriteLine("The index of the added 'myOperation' " + _
                     "operation is : " + _
                     myOperationCollection.IndexOf(myOperation).ToString)
         End If

         myOperationCollection.Remove(myOperation)
         ' Insert the 'myOpearation' operation at the index '0'.
         myOperationCollection.Insert(0, myOperation)
         Console.WriteLine("The operation at index '0' is : " + _
                           myOperationCollection.Item(0).Name)

         Dim myOperationArray(myOperationCollection.Count) As Operation
         myOperationCollection.CopyTo(myOperationArray, 0)
         Console.WriteLine("The operation(s) in the collection are :")
         Dim i As Integer
         For i = 0 To myOperationCollection.Count - 1
            Console.WriteLine(" " + myOperationArray(i).Name)
         Next i

         myDescription.Write("MathService_New_vb.wsdl")
      Catch e As Exception
         Console.WriteLine("Exception caught!!!")
         Console.WriteLine("Source : " + e.Source)
         Console.WriteLine("Message : " + e.Message)
      End Try
   End Sub
End Class

[C#] 
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);
      }
   }
}

[C++] 
#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);
   }
}

[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.

Requirements

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

OperationCollection Members | System.Web.Services.Description Namespace

Show:
© 2014 Microsoft