How to get WS URL from web service method code

I inherited from another team the WCF web service developed on the .net framework 3.5. When installed on a sandbox, the WS URL looks like this:

URL: https: // <EnvironmentName> / fr / webservices / <someWebServiceName> .svc

I was asked to get this URL from the web service method code at runtime. Do you have any ideas?

I would think that there should be an environment variable that can be easily used to get the url. Any fee will be appreciated.

Thank!

+3
source share
3 answers

An OperationContext is available and should provide what you are looking for, in particular:

OperationContext.Current.EndpointDispatcher.EndpointAddress.Uri
+4
source
var context = OperationContext.Current;
var requestedUrl =  context.IncomingMessageHeaders.To.PathAndQuery;
+3
source

[ ]: @MichelZ . :

var context = OperationContext.Current;
string requestedUrl = context.EndpointDispatcher.EndpointAddress.Uri.ToString();

!

0

All Articles