WCF,谁打来的? IIS自托管多个网站,互相调用

发布于 10-20 04:37 字数 882 浏览 6 评论 0原文

我在网站上托管了 WCF 服务。我在同一个网站上有多个绑定。每个网站都可以调用另一个网站上的 WCF 服务。

因此,客户端使用的端点是动态地址。

问:是否可以知道调用者在访问主机时使用的地址是什么?

我正在寻找类似于以下内容的内容,而不必将其作为参数发送。

HttpContext.Current.Request.ServerVariables["SERVER_NAME"]

客户端示例

// The endpoint being called is - 
// http://www.helloworld.com/Services/EchoService.svc for example.  
EchoServiceClient client = new EchoServiceClient("WSHttpBinding_IEchoService", GetEndpoint("EchoService"));
litResponse.Text = client.Echo();
client.Close();

主机示例

public class EchoService : IEchoService
{
    public string Echo()
    {
        return "Echo: " + {something like WCF.Caller.EndPoint.Address};
    }
}

输出类似于

Echo: http://www.helloworld.com

I have a WCF service hosted on a website. I have mutliple bindings on the same website. Each website can call the WCF service on another site.

Because of this, the endpoint the client uses is a dynamic address.

Q: Is it possible to know what the address the caller is using when it hits the host?

I am looking for something similar to the following without having to send it as a param.

HttpContext.Current.Request.ServerVariables["SERVER_NAME"]

Client Example

// The endpoint being called is - 
// http://www.helloworld.com/Services/EchoService.svc for example.  
EchoServiceClient client = new EchoServiceClient("WSHttpBinding_IEchoService", GetEndpoint("EchoService"));
litResponse.Text = client.Echo();
client.Close();

Host Example

public class EchoService : IEchoService
{
    public string Echo()
    {
        return "Echo: " + {something like WCF.Caller.EndPoint.Address};
    }
}

Output similar to

Echo: http://www.helloworld.com

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雨夜星沙2024-10-27 04:37:56

答案是:

System.ServiceModel.OperationContext.Current.IncomingMessageHeaders.To

返回:

http://www.helloworld.com/Services/EchoService.svc

The answer is:

System.ServiceModel.OperationContext.Current.IncomingMessageHeaders.To

Returns:

http://www.helloworld.com/Services/EchoService.svc
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文