I’d like to be able to get the url that the app is hosted on. There will be various ways that clients will access the service layer, through an asp.net mvc app, wcf (hosted on the mvc app).
My service layer is in a dll. Is there any way that I can get the url pointing to a specific action when a remote client uses either entry points to the system?
It is possible – but not a good thing to do. You are binding the business layer to an implementation detail which is higher layers and business layer should have no knowledge of.
You can use various
OperationContext.Currentproperties (depending on your binding) to get to the address.For example,
OperationContext.Current.IncomingMessageHeaderscan be used for HTTP orOperationContext.Current.Host.BaseAddressesif there are base addresses. You just need to evaluate which one provides the address you are looking for depending on your configuration.