Export (0) Print
Expand All

OperationBindingCollection Class

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

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

public sealed class OperationBindingCollection : ServiceDescriptionBaseCollection

The OperationBinding class corresponds to the Web Services Description Language (WSDL) <operation> element enclosed by the <binding> element, which in turn corresponds to the Binding class. For more information about WSDL, see the specification at http://www.w3.org/TR/wsdl/.

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

class MyOperationBindingCollectionSample
{
   static void Main()
   {
      try
      {
         ServiceDescription myServiceDescription =
            ServiceDescription.Read("MathService_input_cs.wsdl");

         // Add the OperationBinding for the Add operation.
         OperationBinding addOperationBinding = new OperationBinding();
         string addOperation = "Add";
         string myTargetNamespace = myServiceDescription.TargetNamespace;
         addOperationBinding.Name = addOperation;

         // Add the InputBinding for the operation.
         InputBinding myInputBinding = new InputBinding();
         SoapBodyBinding mySoapBodyBinding = new SoapBodyBinding();
         mySoapBodyBinding.Use = SoapBindingUse.Literal;
         myInputBinding.Extensions.Add(mySoapBodyBinding);
         addOperationBinding.Input = myInputBinding;

         // Add the OutputBinding for the operation.
         OutputBinding myOutputBinding = new OutputBinding();
         myOutputBinding.Extensions.Add(mySoapBodyBinding);
         addOperationBinding.Output = myOutputBinding;

         // Add the extensibility element for the SoapOperationBinding.
         SoapOperationBinding mySoapOperationBinding = 
            new SoapOperationBinding();
         mySoapOperationBinding.Style = SoapBindingStyle.Document;
         mySoapOperationBinding.SoapAction = myTargetNamespace + addOperation;
         addOperationBinding.Extensions.Add(mySoapOperationBinding);

         // Get the BindingCollection from the ServiceDescription.
         BindingCollection myBindingCollection = 
            myServiceDescription.Bindings;

         // Get the OperationBindingCollection of SOAP binding from  
         // the BindingCollection.
         OperationBindingCollection myOperationBindingCollection = 
            myBindingCollection[0].Operations;

         // Check for the Add OperationBinding in the collection. 
         bool contains = myOperationBindingCollection.Contains
            (addOperationBinding);
         Console.WriteLine("\nWhether the collection contains the Add " +
            "OperationBinding : " + contains);

         // Add the Add OperationBinding to the collection.
         myOperationBindingCollection.Add(addOperationBinding);
         Console.WriteLine("\nAdded the OperationBinding of the Add" +
            " operation to the collection.");

         // Get the OperationBinding of the Add operation from the collection.
         OperationBinding myOperationBinding = 
            myOperationBindingCollection[3];

         // Remove the OperationBinding of the Add operation from  
         // the collection.
         myOperationBindingCollection.Remove(myOperationBinding);
         Console.WriteLine("\nRemoved the OperationBinding of the " +
            "Add operation from the collection.");

         // Insert the OperationBinding of the Add operation at index 0.
         myOperationBindingCollection.Insert(0, addOperationBinding);
         Console.WriteLine("\nInserted the OperationBinding of the " +
            "Add operation in the collection.");

         // Get the index of the OperationBinding of the Add 
         // operation from the collection. 
         int index = myOperationBindingCollection.IndexOf(addOperationBinding);
         Console.WriteLine("\nThe index of the OperationBinding of the " +
            "Add operation : " + index);
         Console.WriteLine("");

         OperationBinding[] operationBindingArray = new
            OperationBinding[myOperationBindingCollection.Count];

         // Copy this collection to the OperationBinding array.
         myOperationBindingCollection.CopyTo(operationBindingArray, 0);
         Console.WriteLine("The operations supported by this service " +
            "are :");
         foreach(OperationBinding myOperationBinding1 in 
            operationBindingArray)
         {
            Binding myBinding = myOperationBinding1.Binding;
            Console.WriteLine(" Binding : "+ myBinding.Name + " Name of " +
               "operation : " + myOperationBinding1.Name);
         }

         // Save the ServiceDescription to an external file.
         myServiceDescription.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 <System.dll>
using namespace System;
using namespace System::Web::Services::Description;

int main()
{
   try
   {
      ServiceDescription* myServiceDescription =
         ServiceDescription::Read(S"MathService_input_cs.wsdl");

      // Add the OperationBinding for the Add operation.
      OperationBinding* addOperationBinding = new OperationBinding();
      String* addOperation = S"Add";
      String* myTargetNamespace = myServiceDescription->TargetNamespace;
      addOperationBinding->Name = addOperation;

      // Add the InputBinding for the operation.
      InputBinding* myInputBinding = new InputBinding();
      SoapBodyBinding* mySoapBodyBinding = new SoapBodyBinding();
      mySoapBodyBinding->Use = SoapBindingUse::Literal;
      myInputBinding->Extensions->Add(mySoapBodyBinding);
      addOperationBinding->Input = myInputBinding;

      // Add the OutputBinding for the operation.
      OutputBinding* myOutputBinding = new OutputBinding();
      myOutputBinding->Extensions->Add(mySoapBodyBinding);
      addOperationBinding->Output = myOutputBinding;

      // Add the extensibility element for the SoapOperationBinding.
      SoapOperationBinding* mySoapOperationBinding =
         new SoapOperationBinding();
      mySoapOperationBinding->Style = SoapBindingStyle::Document;
      mySoapOperationBinding->SoapAction = String::Concat(myTargetNamespace, addOperation);
      addOperationBinding->Extensions->Add(mySoapOperationBinding);

      // Get the BindingCollection from the ServiceDescription.
      BindingCollection* myBindingCollection =
         myServiceDescription->Bindings;

      // Get the OperationBindingCollection of SOAP binding from
      // the BindingCollection.
      OperationBindingCollection* myOperationBindingCollection =
         myBindingCollection->Item[0]->Operations;

      // Check for the Add OperationBinding in the collection.
      bool contains = myOperationBindingCollection->Contains(addOperationBinding);
      Console::WriteLine( S"\nWhether the collection contains the Add OperationBinding : {0}", __box(contains));

      // Add the Add OperationBinding to the collection.
      myOperationBindingCollection->Add(addOperationBinding);
      Console::WriteLine(S"\nAdded the OperationBinding of the Add"
         S" operation to the collection.");

      // Get the OperationBinding of the Add operation from the collection.
      OperationBinding* myOperationBinding =
         myOperationBindingCollection->Item[3];

      // Remove the OperationBinding of the Add operation from
      // the collection.
      myOperationBindingCollection->Remove(myOperationBinding);
      Console::WriteLine(S"\nRemoved the OperationBinding of the "
         S"Add operation from the collection.");

      // Insert the OperationBinding of the Add operation at index 0.
      myOperationBindingCollection->Insert(0, addOperationBinding);
      Console::WriteLine(S"\nInserted the OperationBinding of the "
         S"Add operation in the collection.");

      // Get the index of the OperationBinding of the Add
      // operation from the collection.
      int index = myOperationBindingCollection->IndexOf(addOperationBinding);
      Console::WriteLine(S"\nThe index of the OperationBinding of the Add operation : {0}", __box(index));
      Console::WriteLine(S"");

      OperationBinding* operationBindingArray[] = new
         OperationBinding*[myOperationBindingCollection->Count];

      // Copy this collection to the OperationBinding array.
      myOperationBindingCollection->CopyTo(operationBindingArray, 0);
      Console::WriteLine(S"The operations supported by this service "
         S"are :");
      System::Collections::IEnumerator* myEnum = operationBindingArray->GetEnumerator();
      while (myEnum->MoveNext())
      {
         OperationBinding* myOperationBinding1 = __try_cast<OperationBinding*>(myEnum->Current);
         Binding* myBinding = myOperationBinding1->Binding;
         Console::WriteLine(String::Format( S" Binding : {0} Name of operation : {1}", myBinding->Name, myOperationBinding1->Name ));
      }

      // Save the ServiceDescription to an external file.
      myServiceDescription->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

Community Additions

ADD
Show:
© 2015 Microsoft