Export (0) Print
Expand All

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)

public sealed class OperationBinding : NamedItem
public final class OperationBinding extends NamedItem
public final class OperationBinding extends NamedItem
Not applicable.

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

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

class MyOperationBindingSample
{
    public static void main(String[] args)
    {
        try {
            ServiceDescription myServiceDescription = ServiceDescription.
                Read("MathService_input_jsl.wsdl");
            String myTargetNamespace = myServiceDescription.
                get_TargetNamespace();
            // Create an OperationBinding for the Add operation.
            OperationBinding addOperationBinding = new OperationBinding();
            String addOperation = "Add";
            addOperationBinding.set_Name(addOperation);
            // Create an InputBinding for the Add operation.
            InputBinding myInputBinding = new InputBinding();
            SoapBodyBinding mySoapBodyBinding = new SoapBodyBinding();
            mySoapBodyBinding.set_Use(SoapBindingUse.Literal);
            myInputBinding.get_Extensions().Add(mySoapBodyBinding);
            // Add the InputBinding to the OperationBinding.
            addOperationBinding.set_Input(myInputBinding);
            // Create an OutputBinding for the Add operation.
            OutputBinding myOutputBinding = new OutputBinding();
            myOutputBinding.get_Extensions().Add(mySoapBodyBinding);
            // Add the OutputBinding to the OperationBinding. 
            addOperationBinding.set_Output(myOutputBinding);
            // Create an extensibility element for a SoapOperationBinding.
            SoapOperationBinding mySoapOperationBinding = 
                new SoapOperationBinding();
            mySoapOperationBinding.set_Style(SoapBindingStyle.Document);
            mySoapOperationBinding.set_SoapAction(myTargetNamespace 
                + addOperation);
            // Add the extensibility element SoapOperationBinding to 
            // the OperationBinding.
            addOperationBinding.get_Extensions().Add(mySoapOperationBinding);
            ServiceDescriptionFormatExtensionCollection myExtensions;
            // Get the FaultBindingCollection from the OperationBinding.
            FaultBindingCollection myFaultBindingCollection = 
                addOperationBinding.get_Faults();
            FaultBinding myFaultBinding = new FaultBinding();
            myFaultBinding.set_Name("ErrorFloat");
            // Associate SOAP fault binding to the fault binding 
            // of the operation.
            myExtensions = myFaultBinding.get_Extensions();
            SoapFaultBinding mySoapFaultBinding = new SoapFaultBinding();
            mySoapFaultBinding.set_Use(SoapBindingUse.Literal);
            mySoapFaultBinding.set_Namespace(myTargetNamespace);
            myExtensions.Add(mySoapFaultBinding);
            myFaultBindingCollection.Add(myFaultBinding);
            // Get the BindingCollection from the ServiceDescription.
            BindingCollection myBindingCollection = myServiceDescription.
                get_Bindings();
            // Get the OperationBindingCollection of SOAP binding 
            // from the BindingCollection.
            OperationBindingCollection myOperationBindingCollection = 
                myBindingCollection.get_Item(0).get_Operations();
            myOperationBindingCollection.Add(addOperationBinding);
            Console.WriteLine("The operations supported by this service are:");
            OperationBinding myOperationBinding = null;
            for (int iCtr1 = 0; iCtr1 < myOperationBindingCollection.
                get_Count(); iCtr1++) {
                myOperationBinding = myOperationBindingCollection.
                    get_Item(iCtr1);
                Binding myBinding = myOperationBinding.get_Binding();
                Console.WriteLine(" Binding : " + myBinding.get_Name() 
                    + " :: Name of operation : " 
                    + myOperationBinding.get_Name());
                FaultBindingCollection myFaultBindingCollection1 = 
                    myOperationBinding.get_Faults();
                FaultBinding myFaultBinding1 = null;
                for (int iCtr2 = 0; iCtr2 < myFaultBindingCollection1.
                    get_Count(); iCtr2++) {
                    myFaultBinding1 = myFaultBindingCollection1.get_Item(iCtr2);
                    Console.WriteLine("    Fault : " 
                        + myFaultBinding1.get_Name());
                }
            }
            // Save the ServiceDescripition to an external file.
            myServiceDescription.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
} //MyOperationBindingSample

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