我有一个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
中没有提供的标头。
我在这里和其他地方搜索得到的代码段。 请问我在做什么错了?
谢谢