确定哪些WCF终结正在服务器上使用器上、WCF

2023-09-03 00:25:18 作者:年轻人玩的就是心跳

我有一个WCF服务,这就是曝光使用两个端点的服务。一个端点用于,而另一个是用其余的web服务调用。

I have a wcf service thats exposing a service using two endpoints. One endpoint is used for web service calls while the other is using rest.

有没有办法来确定从哪个端点服务器功能被称为?

Is there a way to determine from which endpoint the server functions are being called?

推荐答案

事实上,相反的是我认为 - 实际上它是pretty的容易找出端点服务被称为上。在您的服务方法,增加了code这几行:

Actually, contrary to what I thought - it's actually pretty easy to find out what endpoint the service was called on. In your service method, add these lines of code:

OperationContext oc = OperationContext.Current;

if(oc != null)
{
    string wasCalledOn = oc.EndpointDispatcher.EndpointAddress.Uri.ToString();
}

不过,正如我说:我会用这个非常明智地与防守 - 不开始改变基于什么端点你的方法被调用的服务行为 - 这将是非常糟糕的设计

But as I said : I would use this very wisely and "defensively" - don't start changing service behavior based on what endpoint your method was called on - that would be very bad design!

我想这几个SOAP端点 - 不是100%确定如何其余的将被处理(但很可能相同或非常相似) - !试试吧

I tried this with several SOAP endpoints - not 100% sure how REST will be handled (but most likely the same or very similarly) - try it out!

但对于记录,这应该工作就好了!

But for logging, this should work just fine!