This documentation is archived and is not being maintained.

OperationBinding Class

Provides specifications for protocols and data formats for the messages used in the action supported by the XML Web service. This class cannot be inherited.

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

[XmlFormatExtensionPointAttribute("Extensions")]
public sealed class OperationBinding : NamedItem

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

The following example demonstrates the use of the properties and methods exposed by the OperationBinding class. It takes an existing ServiceDescription and adds support for the SOAP protocol.

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

class MyOperationBindingSample
{
   static void Main()
   {
      try
      {
         ServiceDescription myServiceDescription =
            ServiceDescription.Read("MathService_input_cs.wsdl");
         string myTargetNamespace = myServiceDescription.TargetNamespace;

         // Create an OperationBinding for the Add operation.
         OperationBinding addOperationBinding = new OperationBinding();
         string addOperation = "Add";
         addOperationBinding.Name = addOperation;

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

         // Add the InputBinding to the OperationBinding.
         addOperationBinding.Input = myInputBinding;

         // Create an OutputBinding for the Add operation.
         OutputBinding myOutputBinding = new OutputBinding();
         myOutputBinding.Extensions.Add(mySoapBodyBinding);

         // Add the OutputBinding to the OperationBinding. 
         addOperationBinding.Output = myOutputBinding;

         // Create an extensibility element for a SoapOperationBinding.
         SoapOperationBinding mySoapOperationBinding = 
            new SoapOperationBinding();
         mySoapOperationBinding.Style = SoapBindingStyle.Document;
         mySoapOperationBinding.SoapAction = myTargetNamespace + addOperation;

         // Add the extensibility element SoapOperationBinding to  
         // the OperationBinding.
         addOperationBinding.Extensions.Add(mySoapOperationBinding);

         ServiceDescriptionFormatExtensionCollection myExtensions;

         // Get the FaultBindingCollection from the OperationBinding.
         FaultBindingCollection myFaultBindingCollection =
            addOperationBinding.Faults;
         FaultBinding myFaultBinding = new FaultBinding();
         myFaultBinding.Name = "ErrorFloat";

         // Associate SOAP fault binding to the fault binding of the operation.
         myExtensions = myFaultBinding.Extensions;
         SoapFaultBinding mySoapFaultBinding = new SoapFaultBinding();
         mySoapFaultBinding.Use = SoapBindingUse.Literal;
         mySoapFaultBinding.Namespace = myTargetNamespace;
         myExtensions.Add(mySoapFaultBinding);
         myFaultBindingCollection.Add(myFaultBinding);

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

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

         Console.WriteLine(
            "The operations supported by this service are:");
         foreach(OperationBinding myOperationBinding in 
            myOperationBindingCollection)
         {
            Binding myBinding = myOperationBinding.Binding;
            Console.WriteLine(" Binding : " + myBinding.Name +
               " :: Name of operation : " + myOperationBinding.Name);
            FaultBindingCollection myFaultBindingCollection1 = 
               myOperationBinding.Faults;
            foreach(FaultBinding myFaultBinding1 in 
               myFaultBindingCollection1)
            {
                 Console.WriteLine("    Fault : " + myFaultBinding1.Name);
            }
         }
         // Save the ServiceDescripition 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");
      String* myTargetNamespace = myServiceDescription->TargetNamespace;

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

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

      // Add the InputBinding to the OperationBinding.
      addOperationBinding->Input = myInputBinding;

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

      // Add the OutputBinding to the OperationBinding. 
      addOperationBinding->Output = myOutputBinding;

      // Create an extensibility element for a SoapOperationBinding.
      SoapOperationBinding* mySoapOperationBinding = 
         new SoapOperationBinding();
      mySoapOperationBinding->Style = SoapBindingStyle::Document;
      mySoapOperationBinding->SoapAction = String::Concat( myTargetNamespace, addOperation );

      // Add the extensibility element SoapOperationBinding to 
      // the OperationBinding.
      addOperationBinding->Extensions->Add(mySoapOperationBinding);

      ServiceDescriptionFormatExtensionCollection* myExtensions;

      // Get the FaultBindingCollection from the OperationBinding.
      FaultBindingCollection* myFaultBindingCollection =
         addOperationBinding->Faults;
      FaultBinding* myFaultBinding = new FaultBinding();
      myFaultBinding->Name = S"ErrorFloat";

      // Associate SOAP fault binding to the fault binding of the operation.
      myExtensions = myFaultBinding->Extensions;
      SoapFaultBinding* mySoapFaultBinding = new SoapFaultBinding();
      mySoapFaultBinding->Use = SoapBindingUse::Literal;
      mySoapFaultBinding->Namespace = myTargetNamespace;
      myExtensions->Add(mySoapFaultBinding);
      myFaultBindingCollection->Add(myFaultBinding);

      // 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;
      myOperationBindingCollection->Add(addOperationBinding);

      Console::WriteLine(
         S"The operations supported by this service are:");
      System::Collections::IEnumerator* myEnum = myOperationBindingCollection->GetEnumerator();
      while (myEnum->MoveNext())
      {
         OperationBinding* myOperationBinding = __try_cast<OperationBinding*>(myEnum->Current);
         Binding* myBinding = myOperationBinding->Binding;
         Console::WriteLine(S" Binding : {0} :: Name of operation : {1}", myBinding->Name, myOperationBinding->Name);
         FaultBindingCollection* myFaultBindingCollection1 = 
            myOperationBinding->Faults;
         System::Collections::IEnumerator* myEnum1 = myFaultBindingCollection1->GetEnumerator();
         while (myEnum1->MoveNext())
         {
            FaultBinding* myFaultBinding1 = __try_cast<FaultBinding*>(myEnum1->Current);
            Console::WriteLine(S"    Fault : {0}", myFaultBinding1->Name);
         }
      }
      // Save the ServiceDescripition 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
Show: