Silverlight中利用WCF获取客户端IP
来源:互联网 发布:淘宝上的瘦身贴有用吗 编辑:程序博客网 时间:2024/05/24 07:35
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); }}