Поделиться через


WebServiceBindingAttribute Класс

Определение

Объявляет привязку, определяющую один или несколько методов веб-службы XML. Этот класс не может быть унаследован.

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, AllowMultiple=true)>]
type WebServiceBindingAttribute = class
    inherit Attribute
[<System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Interface, AllowMultiple=true)>]
type WebServiceBindingAttribute = class
    inherit Attribute
Public NotInheritable Class WebServiceBindingAttribute
Inherits Attribute
Наследование
WebServiceBindingAttribute
Атрибуты

Примеры

Следующая веб-служба XML реализует операции из четырех привязок. В частности, веб-служба XML объявляет три привязки, которые он реализует операции, применяя три WebServiceBindingAttribute атрибута к веб-службе XML.

Чтобы указать, для какой привязки реализуется метод веб-службы XML, SoapDocumentMethodAttribute применяется к каждому из методов веб-службы XML, за исключением DefaultBindingMethod. Не указывая привязку для DefaultBindingMethod, она реализует операцию по привязке по умолчанию для веб-службы XML.

<%@ 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

Комментарии

Привязка, определяемая языком описания веб-служб (WSDL), аналогична интерфейсу, что определяет конкретный набор операций. Каждый метод веб-службы XML является операцией в определенной привязке. Методы веб-службы XML являются членами привязки по умолчанию для веб-службы XML или привязки, указанной в WebServiceBindingAttribute классе, реализующего веб-службу XML. Веб-служба XML может реализовать несколько привязок, применяя несколько WebServiceBindingAttribute атрибутов к веб-службе XML.

После применения одного или нескольких WebServiceAttribute атрибутов к веб-службе XML можно применить к отдельным методам веб-службы XML, чтобы указать операцию привязки, SoapDocumentMethodAttributeSoapRpcMethodAttribute реализованную определенным методом веб-службы XML. Binding Задайте свойство SoapDocumentMethodAttribute или SoapRpcMethodAttribute укажите привязку метода веб-службы XML для реализации операции.

Конструкторы

Имя Описание
WebServiceBindingAttribute()

Инициализирует новый экземпляр класса WebServiceBindingAttribute.

WebServiceBindingAttribute(String, String, String)

Инициализирует новый экземпляр класса WebServiceBindingAttribute.

WebServiceBindingAttribute(String, String)

Инициализирует новый экземпляр класса WebServiceBindingAttribute.

WebServiceBindingAttribute(String)

Инициализирует новый экземпляр WebServiceBindingAttribute класса, задающий имя привязки, реализуемой методом веб-службы XML.

Свойства

Имя Описание
ConformsTo

Возвращает или задает спецификацию взаимодействия веб-служб (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)

Применяется к

См. также раздел