我在家里使用WCF做通讯,里面需要WCF做客户端的IP,经过在服务器上进行了修改,我却发现WCF 3.0 里面并不支持这个功能。没事上周在微软官网下的3.5的新版WCF中提供了WCF IP这个方法。
不说废话,直接看如何实现WCF IP。简单定义一个WCF IP服务:
- 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
- {
- public class MyService : IService
- {
- public string GetData(string value)
- {
- 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);
- }
- }
- }
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
【编辑推荐】
- 1.