WCF3.5获取客户端IP
1
using System;2
using System.Collections.Generic;3
using System.Linq;using System.Runtime.Serialization;4
using System.ServiceModel;5
using System.Text;6
using System.ServiceModel.Channels;7

8
namespace ClientInfoSample9


{10
public class MyService : IService11

{12
public string GetData(string value)13

{14
OperationContext context = OperationContext.Current;15

16
MessageProperties messageProperties = context.IncomingMessageProperties;17

18
RemoteEndpointMessageProperty endpointProperty =19

20
messageProperties[RemoteEndpointMessageProperty.Name]21

22
as RemoteEndpointMessageProperty; 23

24
return string.Format("Hello {0}! Your IP address is {1} and your port is {2}",25

26
value, endpointProperty.Address, endpointProperty.Port);27

28
}29
}30
}31

32

33
using System;34
using System.Collections.Generic;35
using System.Linq;36
using System.Runtime.Serialization;37
using System.ServiceModel;38
using System.Text;39

40
namespace ClientInfoSample41


{42
[ServiceContract]43
public interface IService44

{45
[OperationContract]46
string GetData(string value);47
}48
}49

50

51

52

浙公网安备 33010602011771号