如何在WCF中获取客户端地址? [英] How to get Client Address in WCF?
本文介绍了如何在WCF中获取客户端地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我正在开发一个到WCF迁移项目的Web服务。在我的旧Web服务中,我有以下代码来获取客户端IP地址
Hi All,
I am working on a web service to WCF migration project. In my old web service, I have following piece of code for gettign the client IP address
Context.Request.ServerVariables["REMOTE_ADDR"])
我在Windows服务中托管我的新WCF服务,并使用nettcpBinding(net.tcp)来获得更好的性能。
我担心的是我想用新代码替换aboce代码以获取WCF中的客户端IP地址。
I已经尝试过了。
I am hosting my new WCF service in a Windows service and using nettcpBinding(net.tcp) for better performance.
My concern is I want to replace the aboce piece of code with new code for getting the Client IP address in WCF.
Things I have tried already.
public string GetClientIPAddress()
{
return ((RemoteEndpointMessageProperty)OperationContext.Current.IncomingMessageProperties[RemoteEndpointMessageProperty.Name]).Address;
}
但它以格式:: 1(IPv6) <返回IP地址br />
无论如何以IPv4格式获取客户端IP地址(11.12.13.140)?
提前致谢。
快乐编码
推荐答案
创建IPv6寻址以扩展所有可能的IP地址的总数。 IPv4 不是不同形式的地址。得到了提示?
请参阅: http://en.wikipedia .org / wiki / IPv6 [ ^ ]。< br $>
-SA
IPv6 addressing was created to extend the total number of all possible IP addresses. IPv4 is not a different form of address. Got the hint?
Please see: http://en.wikipedia.org/wiki/IPv6[^].
—SA
这篇关于如何在WCF中获取客户端地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文