如何识别调用您的操作的WCF端点?
如果您的服务器在不同的地址上承载多个相同类型的端点,那么是否可以识别特定请求来自的地址?比如说记录日志 人为的例子:如何识别调用您的操作的WCF端点?,wcf,Wcf,如果您的服务器在不同的地址上承载多个相同类型的端点,那么是否可以识别特定请求来自的地址?比如说记录日志 人为的例子: _serviceHost = new ServiceHost( typeof(Service), new Uri("http://localhost:8000/SomeAddress")); _serviceHost.AddServiceEndpoint( typeof(IService), new BasicHttpBinding(),
_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?
}
}
我不希望创建一个singleton实例并用id传递它。当然,您可以从类似的网站获得此信息:
EndpointAddress address = OperationContext.Current.EndpointDispatcher.EndpointAddress;
Debug.WriteLine(address.Uri);