共用方式為


SoapRpcMethodAttribute.Binding 屬性

定義

取得或設定 XML Web Service 方法實作作業的繫結。

public:
 property System::String ^ Binding { System::String ^ get(); void set(System::String ^ value); };
public string Binding { get; set; }
member this.Binding : string with get, set
Public Property Binding As String

屬性值

String

XML Web Service 方法實作作業的繫結。 預設為附有 SOAP 的 XML Web Service 名稱。

範例

下列程式碼範例示範如何在 XML Web 服務內實作多個系結。

<%@ WebService Language="C#" class="BindingSample" %>
 using System;
 using System.Web.Services;
 using System.Web.Services.Protocols;

 // Binding is defined in this XML Web service and uses the default namespace.
 [ WebServiceBinding(Name="LocalBinding")]
 // Binding is defined in this XML Web service, but not a part of the default namespace.
 [ WebServiceBinding(Name="LocalBindingNonDefaultNamespace", Namespace="http://www.contoso.com/MyBinding")]
 // Binding is defined on a remote server, but this XML Web service implements at least one operation in that binding.
 [ WebServiceBinding(Name="RemoteBinding",Namespace="http://www.contoso.com/MyBinding",Location="http://www.contoso.com/MySevice.asmx?wsdl")]
 public class BindingSample  {

      [ SoapRpcMethod(Binding="LocalBinding")]
      [ WebMethod ]
      public string LocalBindingMethod() {
            return "Member of binding defined in this XML Web service and member of the default namespace";
      }
      [ SoapRpcMethodAttribute(Binding="LocalBindingNonDefaultNamespace")] 
      [ WebMethod ]
      public string LocalBindingNonDefaultNamespaceMethod() {
            return "Member of binding defined in this XML Web service, but a part of a different namespace";
      }

     [ SoapRpcMethodAttribute(Binding="RemoteBinding")] 
     [ WebMethod ]
      public string RemoteBindingMethod() {
            return "Member of a binding defined on another server";
      }

      [ WebMethod  ]
      public string DefaultBindingMethod() {
            return "Member of the default binding";
      }
 
 }
<%@ WebService Language="VB" class="BindingSample" %>
 Imports System.Web.Services
 Imports System.Web.Services.Protocols

 ' Three bindings are defined
   < WebServiceBinding(Name:="LocalBinding"), _
   WebServiceBinding(Name:="LocalBindingNonDefaultNamespace",Namespace:="http://www.contoso.com/MyBinding"), _
   WebServiceBinding(Name:="RemoteBinding",Namespace:="http://www.contoso.com/MyBinding",Location:="http://www.contoso.com/MySevice.asmx?wsdl")> _
 Public class BindingSample  

      < SoapRpcMethod(Binding:="LocalBinding"), WebMethod > _
      Public Function LocalBindingMethod() As String
            Return "Member of binding defined in this XML Web service and member of the default namespace"
          End Function

          < SoapRpcMethodAttribute(Binding:="LocalBindingNonDefaultNamespace"), WebMethod > _
      Public Function LocalBindingNonDefaultNamespaceMethod() As String
        Return "Member of binding defined in this XML Web service, but a part of a different namespace"
      End Function
    
          < SoapRpcMethodAttribute(Binding:="RemoteBinding"), WebMethod > _
      Public Function RemoteBindingMethod() As String
        Return "Member of a binding defined on another server"
      End Function

          < WebMethod > _
      Public Function DefaultBindingMethod() As String
        Return "Member of the default binding"
      End Function
End Class

備註

系結如 Web 服務描述語言 (WSDL) 所定義,類似于其定義一組具體作業的介面。 針對 ASP.NET,每個 XML Web 服務方法是系結內的作業。 XML Web 服務方法是 XML Web 服務的預設系結成員,或套用至 XML Web 服務內 WebServiceBindingAttribute 所指定的系結成員。 如果多個屬性套用至 XML Web 服務,XML Web 服務可以實作多個 WebServiceBindingAttribute 系結。

一或多個 WebServiceBindingAttribute 屬性套用至 XML Web 服務之後, SoapDocumentMethodAttributeSoapRpcMethodAttribute 可以套用至個別的 XML Web 服務方法,以指出特定 XML Web 服務方法所實作的系結作業。 Binding設定 或 SoapRpcMethodAttribute 的 屬性 SoapDocumentMethodAttribute ,以指定 XML Web 服務方法實作作業的系結。 只有一個 SoapDocumentMethodAttributeSoapRpcMethodAttribute 可以套用至 XML Web 服務方法。 因此,XML Web 服務方法只能針對一個系結實作作業。

適用於

另請參閱