using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.Text; namespace ClientInfoSample { [ServiceContract] publicinterface IService { [OperationContract] string GetData(string value); } }
在建立通道之后按照可以取得:
using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.Text; using System.ServiceModel.Channels; namespace ClientInfoSample { publicclass MyService : IService { publicstring GetData(string value) { OperationContext context = OperationContext.Current; MessageProperties essageProperties = context.IncomingMessageProperties; RemoteEndpointMessageProperty endpointProperty = messageProperties [RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty; returnstring.Format("Hello {0}! Your IP address is {1} and your port is {2}", value, endpointProperty.Address, endpointProperty.Port); } } }