次の方法で共有


OperationBinding クラス

XML Web サービスでサポートされているアクションで使用するメッセージのための、プロトコルとデータ形式の仕様を提供します。このクラスは継承できません。

この型のすべてのメンバの一覧については、OperationBinding メンバ を参照してください。

System.Object
   System.Web.Services.Description.DocumentableItem
      System.Web.Services.Description.OperationBinding

NotInheritable Public Class OperationBinding
   Inherits DocumentableItem
[C#]
public sealed class OperationBinding : DocumentableItem
[C++]
public __gc __sealed class OperationBinding : public
   DocumentableItem
[JScript]
public class OperationBinding extends DocumentableItem

スレッドセーフ

この型の public static (Visual Basicでは Shared) のすべてのメンバは、マルチスレッド操作で安全に使用できます。インスタンスのメンバの場合は、スレッドセーフであるとは限りません。

解説

OperationBinding クラスは、 <binding> 要素で囲まれた WSDL (Web Services Description Language) <operation> 要素に対応します。さらに、この要素は Binding クラスに対応します。WSDL の詳細については、http://www.w3.org/TR/wsdl/ の仕様を参照してください。

使用例

[Visual Basic, C#, C++] OperationBinding クラスによって公開されるプロパティとメソッドを使用する例を次に示します。この例では、既存の ServiceDescription に SOAP プロトコルのサポートを追加します。

 
Imports System
Imports System.Web.Services.Description

Class MyOperationBindingSample

   Shared Sub Main()
      Try
         Dim myServiceDescription As ServiceDescription = _
            ServiceDescription.Read("MathService_input_vb.wsdl")
         Dim myTargetNamespace As String = _
            myServiceDescription.TargetNamespace

         ' Create an OperationBinding for the Add operation.
         Dim addOperationBinding As New OperationBinding()
         Dim addOperation As String = "Add"
         addOperationBinding.Name = addOperation

         ' Create an InputBinding for the Add operation.
         Dim myInputBinding As New InputBinding()
         Dim mySoapBodyBinding As 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.
         Dim myOutputBinding As New OutputBinding()
         myOutputBinding.Extensions.Add(mySoapBodyBinding)

         ' Add the OutputBinding to the OperationBinding.
         addOperationBinding.Output = myOutputBinding

         ' Create an extensibility element for a SoapOperationBinding.
         Dim mySoapOperationBinding As New SoapOperationBinding()
         mySoapOperationBinding.Style = SoapBindingStyle.Document
         mySoapOperationBinding.SoapAction = myTargetNamespace & addOperation

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

         Dim myExtensions As ServiceDescriptionFormatExtensionCollection

         ' Get the FaultBindingCollection from the OperationBinding.
         Dim myFaultBindingCollection As FaultBindingCollection = _
            addOperationBinding.Faults
         Dim myFaultBinding As New FaultBinding()
         myFaultBinding.Name = "ErrorFloat"

         ' Associate SOAP fault binding to the fault binding of the operation.
         myExtensions = myFaultBinding.Extensions
         Dim mySoapFaultBinding As New SoapFaultBinding()
         mySoapFaultBinding.Use = SoapBindingUse.Literal
         mySoapFaultBinding.Namespace = myTargetNamespace
         myExtensions.Add(mySoapFaultBinding)
         myFaultBindingCollection.Add(myFaultBinding)

         ' Get the BindingCollection from the ServiceDescription.
         Dim myBindingCollection As BindingCollection = _
            myServiceDescription.Bindings

         ' Get the OperationBindingCollection of SOAP binding 
         ' from the BindingCollection.
         Dim myOperationBindingCollection As OperationBindingCollection = _
            myBindingCollection(0).Operations
         myOperationBindingCollection.Add(addOperationBinding)

         Console.WriteLine( _
            "The operations supported by this service are:")
         Dim myOperationBinding As OperationBinding
         For Each myOperationBinding In  myOperationBindingCollection
            Dim myBinding As Binding = myOperationBinding.Binding
            Console.WriteLine(" Binding : " & myBinding.Name & _
               " :: Name of operation : " & myOperationBinding.Name)
            Dim myFaultBindingCollection1 As FaultBindingCollection = _
               myOperationBinding.Faults
            Dim myFaultBinding1 As FaultBinding
            For Each myFaultBinding1 In myFaultBindingCollection1
               Console.WriteLine("    Fault : " & myFaultBinding1.Name)
            Next myFaultBinding1
         Next myOperationBinding

         ' Save the ServiceDescripition to an external file.
         myServiceDescription.Write("MathService_new_vb.wsdl")
      Catch e As Exception
         Console.WriteLine("Exception caught!!!")
         Console.WriteLine("Source : " & e.Source.ToString())
         Console.WriteLine("Message : " & e.Message.ToString())
      End Try
   End Sub 'Main
End Class 'MyOperationBindingSample

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

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

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

名前空間: System.Web.Services.Description

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

アセンブリ: System.Web.Services (System.Web.Services.dll 内)

参照

OperationBinding メンバ | System.Web.Services.Description 名前空間