问题描述
我在标记为IsOneWay的WCF REST服务中遇到了意外行为. I'm experiencing an unexpected behavior within a WCF REST service that is marked as IsOneWay. 我正在将参数添加到客户端的请求标头中,在服务器端,我试图通过 I am adding params to the request headers from the client, on the server side I'm trying to access these via 知道我如何仍可以通过设置IsOneWay来访问标题吗? Any idea how I can still access the headers with IsOneWay set? 这篇关于IsOneWay WCF REST服务上的WebOperationContext.Current.IncomingRequest.Headers为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! WebOperationContext.Current.IncomingRequest.Headers
来访问这些标头.按照标准服务方法,Headers集合为 填充并具有我设置的标题.但是,当我将方法更改为IsOneWay时, WebOperationContext.Current.IncomingRequest.Headers
为空.WebOperationContext.Current.IncomingRequest.Headers
. On a standard service method, the Headers collection is filled and has the headers that I have set. When I change the method to IsOneWay however, WebOperationContext.Current.IncomingRequest.Headers
is empty.// Works
[WebInvoke(UriTemplate = "MyMethod/{id}")]
public void MyMethod(string id, object data)
{
WebOperationContext.Current.IncomingRequest.Headers.Count; // > 1
}
// Fails
[WebInvoke(UriTemplate = "MyMethod/{id}")]
[OperationContract(IsOneWay = true)] // <-- This is the issue
public void MyMethod(string id, object data)
{
WebOperationContext.Current.IncomingRequest.Headers.Count; // 0
}推荐答案