首页 > 其他 > 详细

wcf 获取客户端 IP

时间:2015-02-02 17:32:52      阅读:297      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!