首页 > 代码库 > wcf 获取客户端 IP
wcf 获取客户端 IP
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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。