1

I am trying to find the url the client used to get to the server, (on the server side). I have tried the following:

Uri url = OperationContext.Current.Channel.RemoteAddress.Uri;
Uri url = OperationContext.Current.Channel.Local.Uri;
Uri url = OperationContext.Current.EndpointDispatcher.EndpointAddress.Uri;

but none of these seemed to work correctly. They all return the server name, (with the fully qualifed domain. such as myserver.mydomain.local. Even if I used used myserver/myservice.svc it would get the full name.

At this point I don't have a service and domain available to test going to mywebsite.com/myservice.svc to see if it has the machine name or not.

The result I want to get (from the server would be):

http://mywebsite.com/myservice.svc

rather than

http://myserver.mydomain.local/myservice.svc

which is what seems to be happening at the moment.

Jon
  • 15,110
  • 28
  • 92
  • 132
  • Jon. I have the same problem. Did this question has been solve? – OammieR Jan 31 '14 at 03:19
  • Jon,@OammieR,how you solve the problem ? – KumarHarsh Jan 25 '16 at 08:41
  • Possible duplicate of [Get original request url in WCF REST service](http://stackoverflow.com/questions/9110397/get-original-request-url-in-wcf-rest-service) – Josh Jan 25 '16 at 14:52
  • @KumarHarsh - See this answer: http://stackoverflow.com/questions/9110397/get-original-request-url-in-wcf-rest-service – Josh Jan 25 '16 at 14:52

2 Answers2

0

If you have access to the HttpContext you can use HttpContext.Current.Request.Url.ToString().

0

OperationContext.Current.IncomingMessageHeaders.To

Should give the Uri that client used to connect to the server.

Kiran Mothe
  • 685
  • 5
  • 10