tags:

views:

272

answers:

1

I asked this question: http://stackoverflow.com/questions/935854/get-the-domain-name-of-a-wcf-request

Is it not possible to get the requesting domain from a WCF request? So for anonymous request that do not require authentication, how can I get the domain name?

+1  A: 

I think you have a number of misconception on how TCP/IP works. First, not every computer or process in the world has a URL. So asking "what is the URL of the requester" (as you did in the previous question) is a meaningless question.

It is slightly more meaningful to ask for the DNS name of the machine that originates a request. Not every machine in the internet has a DNS name, but many do. To find out what the DNS name of a machine is, you first need its IP address, which you have if you received a request from the machine over TCP or UDP (since that will include the requester's IP address). You can then perform a reverse DNS lookup to determine the DNS name; whether this gives you anything, or whether the result is correct depends on how the reverse DNS is managed for the requester.

According to this blog entry, you can use the IncomingMessageProperties, looking at RemoteEndpointMessageProperty, to find out what the remote IP is.

Martin v. Löwis
Actually, you still might not have the actual IP address of the requester. You could be getting the address of a proxy server or NAT device.
John Saunders
Good point. I didn't think about that! I guess I was under the impression that the our requests would be coming from a specific domain. I wanted to omplement something like the Google Maps API key. They somehow embed the domain name int he key.
DDiVita