SoapRpcMethodAttribute.Binding 属性

定义

获取或设置 XML Web services 方法为其实现操作的绑定。

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 services 方法为其实现操作的绑定。 默认为追加了“Soap”的 XML Web services 名称。

示例

下面的代码示例演示如何在 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指定 XML Web 服务方法实现操作的绑定的属性SoapDocumentMethodAttribute。 只能应用一个 SoapDocumentMethodAttributeSoapRpcMethodAttribute 只能应用于 XML Web 服务方法。 因此,XML Web 服务方法只能为一个绑定实现操作。

适用于

另请参阅