WebInvokeAttribute Classe
Definição
Representa um atributo que indica que uma operação de serviço é logicamente uma operação de invocação e que ela pode ser chamada pelo modelo de programação REST do WCF.Represents an attribute indicating that a service operation is logically an invoke operation and that it can be called by the WCF REST programming model.
public ref class WebInvokeAttribute sealed : Attribute, System::ServiceModel::Description::IOperationBehavior
[System.AttributeUsage(System.AttributeTargets.Method)]
public sealed class WebInvokeAttribute : Attribute, System.ServiceModel.Description.IOperationBehavior
[<System.AttributeUsage(System.AttributeTargets.Method)>]
type WebInvokeAttribute = class
inherit Attribute
interface IOperationBehavior
Public NotInheritable Class WebInvokeAttribute
Inherits Attribute
Implements IOperationBehavior
- Herança
- Atributos
- Implementações
Exemplos
O exemplo a seguir mostra como usar o WebInvokeAttribute atributo.The following example shows how to use the WebInvokeAttribute attribute.
Observação
Como a Method propriedade não é especificada no código a seguir, todas as operações de serviço são mapeadas para o método http post.Because the Method property is not specified in the following code, all service operations are mapped to the HTTP POST method.
[ServiceContract]
public interface ICalculator2
{
[OperationContract]
[WebInvoke]
long Add(long x, long y);
[OperationContract]
[WebInvoke(UriTemplate = "Sub?x={x}&y={y}")]
long Subtract(long x, long y);
[OperationContract]
[WebInvoke(UriTemplate = "Mult?x={x}&y={y}", BodyStyle = WebMessageBodyStyle.Bare)]
long Multiply(long x, long y);
[OperationContract]
[WebInvoke(UriTemplate = "Div?x={x}&y={y}", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Xml, ResponseFormat=WebMessageFormat.Xml)]
long Divide(long x, long y);
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "Mod?x={x}&y={y}")]
long Mod(long x, long y);
}
<ServiceContract()> _
Public Interface ICalculator2
<OperationContract()> _
<WebInvoke()> _
Function Add(ByVal x As Long, ByVal y As Long) As Long
<OperationContract()> _
<WebInvoke(UriTemplate:="Sub?x={x}&y={y}")> _
Function Subtract(ByVal x As Long, ByVal y As Long) As Long
<OperationContract()> _
<WebInvoke(UriTemplate:="Mult?x={x}&y={y}", BodyStyle:=WebMessageBodyStyle.Bare)> _
Function Multiply(ByVal x As Long, ByVal y As Long) As Long
<OperationContract()> _
<WebInvoke(UriTemplate:="Div?x={x}&y={y}", BodyStyle:=WebMessageBodyStyle.Bare, RequestFormat:=WebMessageFormat.Xml, ResponseFormat:=WebMessageFormat.Xml)> _
Function Divide(ByVal x As Long, ByVal y As Long) As Long
<OperationContract()> _
<WebInvoke(Method:="POST", UriTemplate:="Mod?x={x}&y={y}")> _
Function Modulo(ByVal x As Long, ByVal y As Long) As Long
End Interface
Comentários
O WebInvokeAttribute atributo é aplicado a uma operação de serviço além de OperationContractAttribute e associa a operação a um UriTemplate , bem como um verbo de transporte subjacente que representa uma invocação (por exemplo, http post, PUT ou Delete).The WebInvokeAttribute attribute is applied to a service operation in addition to the OperationContractAttribute and associates the operation with a UriTemplate as well as an underlying transport verb that represents an invocation (for example, HTTP POST, PUT, or DELETE). O WebInvokeAttribute atributo é um comportamento de operação passiva (os IOperationBehavior métodos não fazem nada) que adiciona metadados à descrição da operação.The WebInvokeAttribute attribute is a passive operation behavior (the IOperationBehavior methods do nothing) that adds metadata to the operation description. A aplicação do WebInvokeAttribute atributo a uma operação de serviço não tem efeito, a menos que um comportamento que procure esses metadados na descrição da operação (como WebHttpBehavior ) seja adicionado à coleção de comportamento do serviço.Applying the WebInvokeAttribute attribute to a service operation has no effect unless a behavior that looks for this metadata in the operation description (such as WebHttpBehavior) is added to the service's behavior collection. O WebInvokeAttribute determina o método http ao qual uma operação de serviço responde.The WebInvokeAttribute determines what HTTP method that a service operation responds to. Por padrão, todos os métodos que têm a WebInvokeAttribute resposta aplicada a solicitações post.By default, all methods that have the WebInvokeAttribute applied respond to POST requests. A Method propriedade permite que você especifique um método http diferente.The Method property allows you to specify a different HTTP method. Se você quiser que uma operação de serviço responda a GET, use o WebGetAttribute em vez disso.If you want a service operation to respond to GET, use the WebGetAttribute instead.
Construtores
| WebInvokeAttribute() |
Inicializa uma nova instância da classe WebInvokeAttribute.Initializes a new instance of the WebInvokeAttribute class. |
Propriedades
| BodyStyle |
Obtém ou define o estilo do corpo das mensagens enviadas e recebidas da operação de serviço.Gets or sets the body style of the messages that are sent to and from the service operation. |
| IsBodyStyleSetExplicitly |
Obtém a propriedade IsBodyStyleSetExplicitly.Gets the IsBodyStyleSetExplicitly property. |
| IsRequestFormatSetExplicitly |
Obtém a propriedade IsRequestFormatSetExplicitly.Gets the IsRequestFormatSetExplicitly property. |
| IsResponseFormatSetExplicitly |
Obtém a propriedade IsResponseFormatSetExplicitly.Gets the IsResponseFormatSetExplicitly property. |
| Method |
Obtém ou define o método de protocolo (por exemplo, HTTP) que responde a operação de serviço.Gets or sets the protocol (for example HTTP) method the service operation responds to. |
| RequestFormat |
Obtém ou define a propriedade RequestFormat.Gets or sets the RequestFormat property. |
| ResponseFormat |
Obtém ou define a propriedade ResponseFormat.Gets or sets the ResponseFormat property. |
| TypeId |
Quando implementado em uma classe derivada, obtém um identificador exclusivo para este Attribute.When implemented in a derived class, gets a unique identifier for this Attribute. (Herdado de Attribute) |
| UriTemplate |
O modelo de URI (Uniform Resource Identifier) para a operação de serviço.The Uniform Resource Identifier (URI) template for the service operation. |
Métodos
| Equals(Object) |
Retorna um valor que indica se essa instância é igual a um objeto especificado.Returns a value that indicates whether this instance is equal to a specified object. (Herdado de Attribute) |
| GetHashCode() |
Retorna o código hash para a instância.Returns the hash code for this instance. (Herdado de Attribute) |
| GetType() |
Obtém o Type da instância atual.Gets the Type of the current instance. (Herdado de Object) |
| IsDefaultAttribute() |
Quando substituído em uma classe derivada, indica se o valor dessa instância é o valor padrão para a classe derivada.When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class. (Herdado de Attribute) |
| Match(Object) |
Quando substituído em uma classe derivada, retorna um valor que indica se essa instância é igual a um objeto especificado.When overridden in a derived class, returns a value that indicates whether this instance equals a specified object. (Herdado de Attribute) |
| MemberwiseClone() |
Cria uma cópia superficial do Object atual.Creates a shallow copy of the current Object. (Herdado de Object) |
| ToString() |
Retorna uma cadeia de caracteres que representa o objeto atual.Returns a string that represents the current object. (Herdado de Object) |