retrieve client IpAddress in WCF service

438 Views Asked by At

I am trying to utilise a WCF service built in .Net 4.0 with custom business functionality in a html page (using jquery) and want to retrieve the client IPAddress in WCF service whoever is trying to access my service through the defined html page. The WCF Service and html page (utilising the WCF service) are setup/ hosted on the same windows server machine(s) virtuals in IIS.

In the process i am using the below code in WCF service to retrieve the IPAdress information of the client.

Code:

OperationContext context = OperationContext.Current;
MessageProperties properties = context.IncomingMessageProperties;
RemoteEndpointMessageProperty endpoint = properties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
string address = endpoint.Address;

There is a load balancer configured (where the service is deployed on two server machines) and we are utilising a virtual url to access the WCF service.

When trying to access the WCF service through the machine name, the service is able to retrieve the client IPAddress correctly, but when i use the virtual URL (where requests can be processed by load balancer on any of the configured machines), the service is retrieving the server IPAddress instead of client IPAdrress detail.

I am stuck with this issue, and didn't find any property in OperationConetext helpful in retrieving the client IpAddress. Can anyone please help me in resolving my problem.

0

There are 0 best solutions below