我在家里使用WCF做通讯,里面需要WCF做客户端的IP,经过在服务器上进行了修改,我却发现WCF 3.0 里面并不支持这个功能。没事上周在微软官网下的3.5的新版WCF中提供了WCF IP这个方法。
创新互联为企业级客户提高一站式互联网+设计服务,主要包括网站制作、成都网站建设、app开发定制、微信小程序开发、宣传片制作、LOGO设计等,帮助客户快速提升营销能力和企业形象,创新互联各部门都有经验丰富的经验,可以确保每一个作品的质量和创作周期,同时每年都有很多新员工加入,为我们带来大量新的创意。
不说废话,直接看如何实现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);
- }
- }
- }
当前名称:如何建立WCFIP相关客户端
网站URL:http://chengdu.cdxwcx.cn/article/dpjssoi.html