WCF数据服务:如何获取请求的IP地址?

时间:2012-03-14 11:00:59

标签: asp.net .net wcf wcf-data-services

Wcf数据服务中获取请求 IP地址的最佳方法是什么?

我正在使用.Net 4

1 个答案:

答案 0 :(得分:1)

你试过这个吗?

OperationContext context = OperationContext.Current;

MessageProperties prop = context.IncomingMessageProperties; 

RemoteEndpointMessageProperty endpoint = prop[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty; 

string ip = endpoint.Address;