Silverlight中利用WCF获取客户端IP

简介: public class Service1 : IService1{ public string DoWork() { OperationContext operationContext = OperationContext.
public class Service1 : IService1
{
     public string DoWork()
     {
        OperationContext operationContext = OperationContext.Current;
        MessageProperties messageProperties = operationContext.IncomingMessageProperties;
        RemoteEndpointMessageProperty remoteEndpointProperty = messageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
 
        return string.Format("Your IP address is {0} and your port is {1}",remoteEndpointProperty.Address, remoteEndpointProperty.Port);
     }
}



public partial class Page : UserControl
{
    public Page() 
    {
          InitializeComponent();
          ServiceReference1.Service1Client client=new GridSplitterSample.ServiceReference1.Service1Client();
          client.DoWorkCompleted += new EventHandler<GridSplitterSample.ServiceReference1.DoWorkCompletedEventArgs>(client_DoWorkCompleted);
          client.DoWorkAsync();
   }
 
   void client_DoWorkCompleted(object sender, GridSplitterSample.ServiceReference1.DoWorkCompletedEventArgs e)
   {
        TextBlock myBlock=new TextBlock();
        myBlock.Text=e.Result;
        LayoutRoot.children.Add(myBlock);
   }
}


相关文章
|
开发者 开发工具 定位技术
|
XML 网络架构 数据格式
|
数据库 测试技术 安全
使用Entity Framework和WCF Ria Services开发SilverLight之2:POCO
在上一篇中《使用Entity Framework和WCF Ria Services开发SilverLight之1:简单模型》我们提出这类简单模型的几个问题: 1:实体模型被紧耦合在EDM中,同时它不能项目(模块)使用。
1241 0
|
监控
Wcf通讯基础框架方案(三)——客户端
假设定义了一个服务契约: [ServiceContract(Namespace = "WcfExtension.Services.Interface")] public interface ITestService { [OperationContract] ...
718 0