WebOperationContext 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
帮助程序类,提供对 Web 请求和响应的上下文属性的轻松访问。
public ref class WebOperationContext : System::ServiceModel::IExtension<System::ServiceModel::OperationContext ^>
public class WebOperationContext : System.ServiceModel.IExtension<System.ServiceModel.OperationContext>
type WebOperationContext = class
interface IExtension<OperationContext>
Public Class WebOperationContext
Implements IExtension(Of OperationContext)
- 继承
-
WebOperationContext
- 实现
示例
以下代码演示如何检索 UriTemplateMatch 与当前调用的 Web 操作上下文关联的实例。 该代码还演示如何设置传出响应的 HTTP 状态。
counter++;
UriTemplateMatch match = WebOperationContext.Current.IncomingRequest.UriTemplateMatch;
UriTemplate template = new UriTemplate("{id}");
customer.Uri = template.BindByPosition(match.BaseUri, counter.ToString());
customers[counter.ToString()] = customer;
WebOperationContext.Current.OutgoingResponse.SetStatusAsCreated(customer.Uri);
counter = counter + 1
Dim match As UriTemplateMatch = WebOperationContext.Current.IncomingRequest.UriTemplateMatch
Dim template As New UriTemplate("{id}")
customer.Uri = template.BindByPosition(match.BaseUri, counter.ToString())
customers(counter.ToString()) = customer
WebOperationContext.Current.OutgoingResponse.SetStatusAsCreated(customer.Uri)
构造函数
| 名称 | 说明 |
|---|---|
| WebOperationContext(OperationContext) |
使用指定的WebOperationContext实例初始化类的新实例OperationContext。 |
属性
| 名称 | 说明 |
|---|---|
| Current |
获取当前的 Web 操作上下文。 |
| IncomingRequest |
获取所接收请求的 Web 请求上下文。 |
| IncomingResponse |
获取所接收请求的 Web 响应上下文。 |
| OutgoingRequest |
获取所发送请求的 Web 请求上下文。 |
| OutgoingResponse |
获取要发送的响应的 Web 响应上下文。 |