WCF 3.5 find the URL that the client used to access the service (server side)

I am trying to find the URL that the client used to access the server (server side). I 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 them worked correctly. They all return the server name (with a fully qualified domain, for example myserver.mydomain.local. Even if I used myserver / myservice.svc, it would get the full name.

At this moment, I do not have the service and domain available for testing at mywebsite.com/myservice.svc to find out if it has a machine name or not.

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

http://mywebsite.com/myservice.svc

but not

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

what seems to be happening at the moment.

+1
source share
2 answers

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

0
source

OperationContext.Current.IncomingMessageHeaders.To

Must provide the Uri that the client used to connect to the server.

0
source

Source: https://habr.com/ru/post/948779/