WebInvokeAttribute 类
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示属性,该属性指示服务操作在逻辑上是调用操作,而且可由 WCF REST 编程模型调用。
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
- 继承
- 属性
- 实现
下面的示例演示如何使用 WebInvokeAttribute 特性。
备注
在下面的代码中,未指定 Method 属性,因此所有服务操作都会映射到 HTTP POST 方法。
[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
除了 WebInvokeAttribute 之外,OperationContractAttribute 属性也会应用到服务操作,并将该操作与 UriTemplate
以及表示调用的基础传输谓词(如 HTTP POST、PUT 或 DELETE)相关联。 该 WebInvokeAttribute 属性 是被动操作 行为, IOperationBehavior (方法) 不向操作说明添加元数据。 将 WebInvokeAttribute 特性应用到服务操作无任何效果,除非将在操作说明中查找此元数据的行为(如 WebHttpBehavior)添加到服务的行为集合中。 WebInvokeAttribute 会确定服务操作响应的 HTTP 方法。 默认情况下,所有已应用 WebInvokeAttribute 的方法都会响应 POST 请求。 Method 属性允许您指定不同的 HTTP 方法。 如果您希望服务操作响应 GET,请改用 WebGetAttribute。
Web |
初始化 WebInvokeAttribute 类的新实例。 |
Body |
获取或设置传入与传出服务操作的消息的正文样式。 |
Is |
获取 IsBodyStyleSetExplicitly 属性。 |
Is |
获取 IsRequestFormatSetExplicitly 属性。 |
Is |
|
Method |
获取或设置服务操作响应的协议(如 HTTP)方法。 |
Request |
获取或设置 RequestFormat 属性。 |
Response |
获取或设置 ResponseFormat 属性。 |
Type |
在派生类中实现时,获取此 Attribute 的唯一标识符。 (继承自 Attribute) |
Uri |
用于服务操作的统一资源标识符 (URI) 模板。 |
Equals(Object) |
返回一个值,该值指示此实例是否与指定的对象相等。 (继承自 Attribute) |
Get |
返回此实例的哈希代码。 (继承自 Attribute) |
Get |
获取当前实例的 Type。 (继承自 Object) |
Is |
在派生类中重写时,指示此实例的值是否是派生类的默认值。 (继承自 Attribute) |
Match(Object) |
当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。 (继承自 Attribute) |
Memberwise |
创建当前 Object 的浅表副本。 (继承自 Object) |
To |
返回表示当前对象的字符串。 (继承自 Object) |
产品 | 版本 |
---|---|
.NET Framework | 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8 |