tags:

views:

61

answers:

1

If you have a server that host multiple endpoints of the same type at different address. Is it possible to identify the address from which a particular request came? Say for logging purposes?

contrived Example

        _serviceHost = new ServiceHost(
            typeof(Service),
            new Uri("http://localhost:8000/SomeAddress"));

        _serviceHost.AddServiceEndpoint(
            typeof(IService),
            new BasicHttpBinding(),
            string.Empty);

        _serviceHost2 = new ServiceHost(
            typeof(Service),
            new Uri("http://localhost:8000/SomeOtherAddress"));

        _serviceHost2.AddServiceEndpoint(
            typeof(IService),
            new BasicHttpBinding(),
            string.Empty);

[ServiceContract()] public interface IService { [OperationContract] void Operation(); }

public class Service {

void Operation()
{        
    //Which endpoint made this call?
}

}

`

I would rather not create a singleton instance and pass it with an id.

Thanks

+2  A: 

Sure, you can get this information from the OperationContext like so:

EndpointAddress address = OperationContext.Current.EndpointDispatcher.EndpointAddress;

Debug.WriteLine(address.Uri);
Drew Marsh
Great thanks, that will work.
RMK