WCF应用方法比较灵活,可以为开发人员创造一个跨平台的解决方案。我们在这里会为大家详细讲解一下有关WCF获取客户端IP的操作方法,希望对这方面又需要的朋友们可以从中获得一些帮助。

创新互联主要从事成都网站制作、网站设计、外贸网站建设、网页设计、企业做网站、公司建网站等业务。立足成都服务奎文,10年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:028-86922220
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 messageProperties = 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);
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Runtime.Serialization;
- using System.ServiceModel;
- using System.Text;
- namespace ClientInfoSample
- {
- [ServiceContract]
- public interface IService
- {
- [OperationContract]
- string GetData(string value);
- }
- }