嘿,你如何获得发出请求的人的IP地址如下:
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode =
AspNetCompatibilityRequirementsMode.Required)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
public partial class UsersService
{
[WebInvoke(UriTemplate = "", Method = "PUT")]
public User AddNewUser(User newUser)
{
// code goes here including GETTING AN IP??
}
谢谢!
答案 0 :(得分:38)
在AddNewUser内部使用以下代码段:
OperationContext context = OperationContext.Current;
MessageProperties messageProperties = context.IncomingMessageProperties;
RemoteEndpointMessageProperty endpointProperty =
messageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
RemoteEndpointMessageProperty实例提供地址和端口属性。