要了解WCF中连接客户端的信息。
需要了解OperationContext类,
OperationContext中包括:
IncomingMessageHeaders,
MessageHeaders.From,类型为EndPointAddress(发送消息的节点).
EndPointAddress 中有Headers属性。
AddressHeader对象,地址和命名空间。
在网上找到获得客户端IP地址的内容。
OperationContext context = OperationContext.Current;
MessageProperties essageProperties = context.IncomingMessageProperties;
RemoteEndpointMessageProperty endpointProperty =
messageProperties [RemoteEndpointMessageProperty.Name]
as RemoteEndpointMessageProperty;
return string.Format("Hello {0}! Your IP address is {1} and your port is {2}", value, endpointProperty.Address, endpointProperty.Port);