Reputation: 7062
How do I get the web address of the currently running WCF service in code in C#? For instance during the web service call inside the function, I'm looking for "this" and the base address of the currently executing/running service. This service will run on like "http://localhost:2342342/WebServiceName1.svc" and I want to get this address during run-time inside the service in code. The reason why I'm getting the automatic address instead of hardcoded address is because when I put the service into production or moves service, I want to have dynamic address. I want to set extra values using this service address during service initialization.
On another point, is there any unique ID and guid associated with WCF already built in. For instance if I have a same service running on 2 separate servers with web addresses, is there a way to get and set a unique ID for each individual service. Only way is through the address of the services? Same service, multiple servers and different data processing on each individual services.
Upvotes: 0
Views: 766
Reputation:
To know the current address for the WCF within inside the WCF service use the following:
Uri address = OperationContext.Current.IncomingMessageHeaders.To;
Upvotes: 3