Export (0) Print
Expand All

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
public final class OperationCollection extends ServiceDescriptionBaseCollection
public final class OperationCollection extends ServiceDescriptionBaseCollection
Not applicable.

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);
      }
   }
}

import System.*;  
import System.Web.Services.*;  
import System.Xml.*;  
import System.Web.Services.Description.*;  

class MyOperationCollectionSample
{
    public static void main(String[] args)
    {
        try {
            // Read the 'MathService_Input_jsl.wsdl' file.
            ServiceDescription myDescription = ServiceDescription.
                Read("MathService_Input_jsl.wsdl");
            PortTypeCollection myPortTypeCollection = myDescription.
                get_PortTypes();
            // Get the 'OperationCollection' for 'SOAP' protocol.
            OperationCollection myOperationCollection = myPortTypeCollection.
                get_Item(0).get_Operations();
            Operation myOperation = new Operation();
            myOperation.set_Name("Add");
            OperationMessage myOperationMessageInput = (OperationMessage)
                new OperationInput();
            myOperationMessageInput.set_Message(new XmlQualifiedName(
                "AddSoapIn", myDescription.get_TargetNamespace()));
            OperationMessage myOperationMessageOutput = (OperationMessage)
                new OperationOutput();
            myOperationMessageOutput.set_Message(new XmlQualifiedName(
                "AddSoapOut", myDescription.get_TargetNamespace()));
            myOperation.get_Messages().Add(myOperationMessageInput);
            myOperation.get_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.get_Item(0).get_Name());
            Operation myOperationArray[] = new Operation[myOperationCollection.
                get_Count()];
            myOperationCollection.CopyTo(myOperationArray, 0);
            Console.WriteLine("The operation(s) in the collection are :");
            for (int i = 0; i < myOperationCollection.get_Count(); i++) {
                Console.WriteLine(" " + myOperationArray[i].get_Name());
            }
            myDescription.Write("MathService_New_jsl.wsdl");
        }
        catch (System.Exception e) {
            Console.WriteLine("Exception caught!!!");
            Console.WriteLine("Source : " + e.get_Source());
            Console.WriteLine("Message : " + e.get_Message());
        }
    } //main
} //MyOperationCollectionSample

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 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft