WebServiceBindingAttribute 类

定义

声明用于定义一个或多个 XML Web service 方法的绑定。 此类不能被继承。

public ref class WebServiceBindingAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=true)]
public sealed class WebServiceBindingAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Interface, AllowMultiple=true)]
public sealed class WebServiceBindingAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Interface, AllowMultiple=true, Inherited=true)]
public sealed class WebServiceBindingAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=true)>]
type WebServiceBindingAttribute = class
    inherit Attribute
[<System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Interface, AllowMultiple=true)>]
type WebServiceBindingAttribute = class
    inherit Attribute
[<System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Interface, AllowMultiple=true, Inherited=true)>]
type WebServiceBindingAttribute = class
    inherit Attribute
Public NotInheritable Class WebServiceBindingAttribute
Inherits Attribute
继承
WebServiceBindingAttribute
属性

示例

以下 XML Web 服务从四个绑定实现操作。 具体而言,XML Web 服务通过向 XML Web 服务应用三个属性来声明它实现操作的三 WebServiceBindingAttribute 个绑定。

若要指定要为其实现操作的 XML Web 服务方法的绑定, SoapDocumentMethodAttribute 将应用于每个 XML Web 服务方法,但除外 DefaultBindingMethod。 如果不指定绑定, DefaultBindingMethod它将在 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 it is 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  {

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

     [ SoapDocumentMethod(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
Imports System.Web.Services
Imports System.Web.Services.Protocols

' Binding is defined in this XML Web service and uses the default namespace.
' Binding is defined in this XML Web service, but it is not a part of the default
' namespace.
' Binding is defined on a remote server, but this XML Web service implements at
' least one operation in that binding.
<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
    
    <SoapDocumentMethod(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
    
    <SoapDocumentMethod(Binding := "LocalBindingNonDefaultNamespace"), WebMethod()> _
    Public Function LocalBindingNonDefaultNamespaceMethod() As String
    
        Return "Member o1f binding defined in this XML Web service, but a part of a different namespace"
    End Function    
    
    <SoapDocumentMethod(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) 定义的绑定类似于接口,因为它定义了一组具体的操作。 每个 XML Web 服务方法都是特定绑定中的操作。 XML Web 服务方法是 XML Web 服务的默认绑定的成员,或者是应用于实现 XML Web 服务的类中指定的 WebServiceBindingAttribute 绑定。 XML Web 服务可以通过将多个属性应用于 XML Web 服务来实现多个 WebServiceBindingAttribute 绑定。

将一个或多个 WebServiceAttribute 属性应用于 XML Web 服务后, SoapDocumentMethodAttributeSoapRpcMethodAttribute 可应用于单个 XML Web 服务方法,以指示由特定 XML Web 服务方法实现的绑定操作。 设置BindingSoapRpcMethodAttribute指定 XML Web 服务方法正在为其实现操作的绑定的属性SoapDocumentMethodAttribute

构造函数

WebServiceBindingAttribute()

初始化 WebServiceBindingAttribute 类的新实例。

WebServiceBindingAttribute(String)

通过设置 XML Web service 方法实现的绑定的名称,初始化 WebServiceBindingAttribute 类的新实例。

WebServiceBindingAttribute(String, String)

初始化 WebServiceBindingAttribute 类的新实例。

WebServiceBindingAttribute(String, String, String)

初始化 WebServiceBindingAttribute 类的新实例。

属性

ConformsTo

获取或设置绑定声称所符合的 Web 服务互操作性 (WSI) 规范。

EmitConformanceClaims

获取或设置一个值,该值指示绑定是否发出符合性声称。

Location

获取或设置定义绑定的位置。

Name

获取或设置绑定的名称。

Namespace

获取或设置与绑定关联的命名空间。

TypeId

在派生类中实现时,获取此 Attribute 的唯一标识符。

(继承自 Attribute)

方法

Equals(Object)

返回一个值,该值指示此实例是否与指定的对象相等。

(继承自 Attribute)
GetHashCode()

返回此实例的哈希代码。

(继承自 Attribute)
GetType()

获取当前实例的 Type

(继承自 Object)
IsDefaultAttribute()

在派生类中重写时,指示此实例的值是否是派生类的默认值。

(继承自 Attribute)
Match(Object)

当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。

(继承自 Attribute)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

返回表示当前对象的字符串。

(继承自 Object)

显式接口实现

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

将一组名称映射为对应的一组调度标识符。

(继承自 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。

(继承自 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

检索对象提供的类型信息接口的数量(0 或 1)。

(继承自 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供对某一对象公开的属性和方法的访问。

(继承自 Attribute)

适用于

另请参阅