OperationBinding 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
提供規格給使用於 XML Web Service 所支援動作之訊息的通訊協定和資料格式。 此類別無法獲得繼承。
public ref class OperationBinding sealed : System::Web::Services::Description::DocumentableItem
public ref class OperationBinding sealed : System::Web::Services::Description::NamedItem
[System.Web.Services.Configuration.XmlFormatExtensionPoint("Extensions")]
public sealed class OperationBinding : System.Web.Services.Description.DocumentableItem
[System.Web.Services.Configuration.XmlFormatExtensionPoint("Extensions")]
public sealed class OperationBinding : System.Web.Services.Description.NamedItem
[<System.Web.Services.Configuration.XmlFormatExtensionPoint("Extensions")>]
type OperationBinding = class
inherit DocumentableItem
[<System.Web.Services.Configuration.XmlFormatExtensionPoint("Extensions")>]
type OperationBinding = class
inherit NamedItem
Public NotInheritable Class OperationBinding
Inherits DocumentableItem
Public NotInheritable Class OperationBinding
Inherits NamedItem
- 繼承
- 繼承
- 屬性
範例
下列範例示範如何使用 類別所 OperationBinding
公開的屬性和方法。 它會採用現有的 ServiceDescription ,並新增 SOAP 通訊協定的支援。
#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( "MathService_input_cs.wsdl" );
String^ myTargetNamespace = myServiceDescription->TargetNamespace;
// Create an OperationBinding for the Add operation.
OperationBinding^ addOperationBinding = gcnew OperationBinding;
String^ addOperation = "Add";
addOperationBinding->Name = addOperation;
// Create an InputBinding for the Add operation.
InputBinding^ myInputBinding = gcnew InputBinding;
SoapBodyBinding^ mySoapBodyBinding = gcnew 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 = gcnew OutputBinding;
myOutputBinding->Extensions->Add( mySoapBodyBinding );
// Add the OutputBinding to the OperationBinding.
addOperationBinding->Output = myOutputBinding;
// Create an extensibility element for a SoapOperationBinding.
SoapOperationBinding^ mySoapOperationBinding = gcnew 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 = gcnew FaultBinding;
myFaultBinding->Name = "ErrorFloat";
// Associate SOAP fault binding to the fault binding of the operation.
myExtensions = myFaultBinding->Extensions;
SoapFaultBinding^ mySoapFaultBinding = gcnew 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:" );
System::Collections::IEnumerator^ myEnum = myOperationBindingCollection->GetEnumerator();
while ( myEnum->MoveNext() )
{
OperationBinding^ myOperationBinding = safe_cast<OperationBinding^>(myEnum->Current);
Binding^ myBinding = myOperationBinding->Binding;
Console::WriteLine( " 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 = safe_cast<FaultBinding^>(myEnum1->Current);
Console::WriteLine( " Fault : {0}", myFaultBinding1->Name );
}
}
myServiceDescription->Write( "MathService_new_cs.wsdl" );
}
catch ( Exception^ e )
{
Console::WriteLine( "Exception caught!!!" );
Console::WriteLine( "Source : {0}", e->Source );
Console::WriteLine( "Message : {0}", e->Message );
}
}
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 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);
}
}
}
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
End Class
備註
類別 OperationBinding
會對應至元素所括住 <binding>
的 Web 服務描述語言 (WSDL) <operation>
元素,而該專案接著會對應至 Binding 類別。 如需 WSDL 的詳細資訊,請參閱 WSDL 規格。
建構函式
OperationBinding() |
初始化 OperationBinding 類別的新執行個體。 |
屬性
Binding |
取得 Binding,目前 OperationBinding 為其中的成員。 |
Documentation |
取得或設定 DocumentableItem 的執行個體的文字文件。 (繼承來源 DocumentableItem) |
DocumentationElement |
取得或設定 DocumentableItem 的文件項目。 (繼承來源 DocumentableItem) |
ExtensibleAttributes |
取得或設定型別 XmlAttribute 的陣列,表示符合 Web 服務互通性 (WS-I) Basic Profile 1.1 的 WSDL 屬性擴充。 (繼承來源 DocumentableItem) |
Extensions |
取得與目前 OperationBinding 特定的擴充性項目的集合。 |
Faults |
取得與 FaultBindingCollection 執行個體 (Instance) 相關聯的 OperationBinding。 |
Input |
取得或設定與 InputBinding 相關聯的 OperationBinding。 |
Name |
取得或設定 OperationBinding 的名稱。 |
Name |
取得或設定項目的名稱。 (繼承來源 NamedItem) |
Namespaces |
取得或設定命名空間前置詞和命名空間的字典,用於在建構 ServiceDescription 物件時保留命名空間前置詞和命名空間。 (繼承來源 DocumentableItem) |
Output |
取得或設定與 OutputBinding 相關聯的 OperationBinding。 |
方法
Equals(Object) |
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
GetHashCode() |
做為預設雜湊函式。 (繼承來源 Object) |
GetType() |
取得目前執行個體的 Type。 (繼承來源 Object) |
MemberwiseClone() |
建立目前 Object 的淺層複製。 (繼承來源 Object) |
ToString() |
傳回代表目前物件的字串。 (繼承來源 Object) |