向WCF请求添加HTTP请求标头 [英] Adding HTTP request header to WCF request
本文介绍了向WCF请求添加HTTP请求标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个同时由AJAX和C#应用程序使用的WCF服务,
我需要通过HTTP请求标头发送参数.
I have a WCF service consume by both AJAX and C# application,
I need to send a parameter through the HTTP request header.
在我的AJAX上,我添加了以下内容,并且可以正常工作:
On my AJAX I have added the following and it works:
$.ajax({
type: "POST",
url: this.tenantAdminService,
beforeSend: function (req, methodName)
{
req.setRequestHeader("AdminGUID", adminGuid);
}
在WCF服务器端,我执行以下操作以获取标头:
and on the WCF server side I do the following to Get the header:
string adminGUID = System.Web.HttpContext.Current.Request.Headers["AdminGUID"];
C#等效项是什么?如何发送WCF服务器也会使用的http请求标头?
What is the C# equivalent? How can I send the http request header that will also be consume by my WCF server?
我需要将参数添加到HTTP请求标头而不是消息标头中,
I need to add the parameter to HTTP request header and not to the message header,
谢谢!
推荐答案
The simplest way to this is using WebOperationContext at the following way:
Service1Client serviceClient = new Service1Client();
using (new System.ServiceModel.OperationContextScope((System.ServiceModel.IClientChannel)serviceClient.InnerChannel))
{
System.ServiceModel.Web.WebOperationContext.Current.OutgoingRequest.Headers.Add("AdminGUID", "someGUID");
serviceClient.GetData();
}
选自发布
这篇关于向WCF请求添加HTTP请求标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文