码迷,mamicode.com
首页 > 其他好文 > 详细

wcf 获取客户端 IP

时间:2015-02-02 17:35:02      阅读:323      评论:0      收藏:0      [点我收藏+]

标签:

http://stackoverflow.com/questions/3937773/wcf-security-using-client-ip-address

 

var context = OperationContext.Current;
var props = context.IncomingMessageProperties;
var endpoint = props[RemoteEndpointMessageProperty.Name];
return ((RemoteEndpointMessageProperty)endpoint).Address;


You can access HTTP headers in the same way. Instead of RemoteEndpointMessageProperty you have to use HttpRequestMessageProperty. This property contains Headers name value collection so you should be able to get any HTTP header from incoming request.


Ultimately, this answer is valid, so I‘m accepting it, but .NET 3.5 and greater added a WebOperationContext class to the System.ServiceModel.Web namespace which makes this a bit easier. 

Yes, but this solution is general for all Http based bindings. WebOperationContext should work only for REST services (exposed on WebHttpBinding). 

wcf 获取客户端 IP

标签:

原文地址:http://www.cnblogs.com/runliuv/p/4268008.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!