如何建立WCF IP相關(guān)客戶端
作者:佚名
WCF IP其混合了函數(shù)語言和物件導(dǎo)向程序編制語言,并且完美的適用于編程、算法、技術(shù)和探索性開發(fā),因此可以在使用的過程當(dāng)中感受到趣味性和吸引力。
我在家里使用WCF做通訊,里面需要WCF做客戶端的IP,經(jīng)過在服務(wù)器上進(jìn)行了修改,我卻發(fā)現(xiàn)WCF 3.0 里面并不支持這個功能。沒事上周在微軟官網(wǎng)下的3.5的新版WCF中提供了WCF IP這個方法。
不說廢話,直接看如何實現(xiàn)WCF IP。簡單定義一個WCF IP服務(wù):
- 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);
- }
- }
- }
【編輯推薦】
責(zé)任編輯:chenqingxiang
來源:
NET130