请求标头在WCF Web服务中不可用

时间:2018-12-18 16:02:01

标签: c# asp.net web-services

我有一个aspx网页,它将自定义标头添加到我的Web服务的传出请求中:

    using (MyWebServiceClient wsClient = new MyWebsiteWebServiceClient())
    {
        using (new OperationContextScope(wsClient.InnerChannel))
        {
            // Add a HTTP Header to an outgoing request
            HttpRequestMessageProperty requestMessage = new HttpRequestMessageProperty();
            requestMessage.Headers["Authorization"] = Token;
OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessage;

            Session["success"] = wsClient.MyMethod();
        }
    }

据我所知,标头已添加到传出请求中。

我在调用的Web服务中的代码:

public bool MyMethod()
{
    try
    {
        IncomingWebRequestContext request = WebOperationContext.Current.IncomingRequest;
        WebHeaderCollection headers = request.Headers;

     }
     catch (Exception ex)
     {
         return false;
    }
}

获得的headers中没有提供的标头。

我在这里和其他地方搜索得到的代码段。 请问我在做什么错了?

谢谢

0 个答案:

没有答案