【发布时间】:2014-01-15 01:32:34
【问题描述】:
Restful WCF Service中如何获取浏览器名称、浏览器版本、应用程序版本、应用程序名称?将评估上述信息的函数获取一个作为 System.ServiceModel.Channel.Message 的参数。
提前致谢。
【问题讨论】:
Restful WCF Service中如何获取浏览器名称、浏览器版本、应用程序版本、应用程序名称?将评估上述信息的函数获取一个作为 System.ServiceModel.Channel.Message 的参数。
提前致谢。
【问题讨论】:
如果您的应用程序在自定义 HTTP 标头中发送该信息,您将能够通过查看 HttpRequestMessageProperty 来检索它,您可以通过转到其属性从消息对象中检索它:
private static List<KeyValuePair<string, string>> GetHttpHeaders(Message msg)
{
var result = new List<KeyValuePair<string, string>>();
var prop = (HttpRequestMessageProperty)msg.Properties[HttpRequestMessageProperty.Name];
foreach (var headerName in prop.Headers.AllKeys)
{
result.Add(new KeyValuePair<string, string>(
headerName,
prop.Headers[headerName]);
}
return result;
}
【讨论】: