WCF 4休息获取请求IP? [英] WCF 4 Rest Getting IP of Request?

查看:127
本文介绍了WCF 4休息获取请求IP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

哎,你怎么做的东西像下面这样的要求的人的IP地址:

  [的ServiceContract ] 
[AspNetCompatibilityRequirements(RequirementsMode =
AspNetCompatibilityRequirementsMode.Required)
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
公共部分类UsersService
{
[WebInvoke(UriTemplate =,方法=PUT)]
公众用户AddNewUser函数(用户NEWUSER)
{
//代码放在这里,包括获取IP?
}



谢谢!


解决方案
<下面的代码片段p>里面AddNewUser函数使用:

 的OperationContext背景= OperationContext.Current; 
MessageProperties messageProperties = context.IncomingMessageProperties;
RemoteEndpointMessageProperty endpointProperty =
messageProperties [RemoteEndpointMessageProperty.Name]作为RemoteEndpointMessageProperty;



RemoteEndpointMessageProperty实例提供地址和端口属性。


Hey, how do you get the IP address of the person making a request in something like the following:

    [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??
        }

Thanks!

解决方案

Inside AddNewUser use following snippet:

OperationContext context = OperationContext.Current;
MessageProperties messageProperties = context.IncomingMessageProperties;
RemoteEndpointMessageProperty endpointProperty =
  messageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;

RemoteEndpointMessageProperty instance offers Address and Port properties.

这篇关于WCF 4休息获取请求IP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆