简体   繁体   English

在Castle Windsor WCF Facility中,如何访问端点地址?

[英]In Castle Windsor WCF Facility, how do I access endpoint address?

I'm successfully using Castle Windsor WCF Integration Facility in my WCF client application to get a connection to the server and make service requests: 我已在WCF客户端应用程序中成功使用Castle Windsor WCF集成工具来建立与服务器的连接并发出服务请求:

_container = new WindsorContainer();
_container.Kernel.AddFacility<WcfFacility>();
_container.Register(Component
          .For<IService>()
          .AsWcfClient(new DefaultClientModel(WcfEndpoint.FromConfiguration("Service"))));

// ... 

var service = _container.Resolve<IService>();
service.SomeOperation();

However, I'd like to display to the user the endpoint address they're connected to. 但是,我想向用户显示他们连接的端点地址。 With svcutil -generated proxy objects, one can get the address using: 使用svcutil生成的代理对象,可以使用以下方法获取地址:

 var address = client.Endpoint.Address.ToString();

I know I can examine the application config and fetch the endpoint details that way, but is it possible to get it directly from the Castle Windsor proxy object, or from the configuration process? 我知道我可以检查应用程序配置并以这种方式获取端点详细信息,但是是否可以直接从Castle Windsor代理对象或配置过程中获取它?

Well, if you really have to, there's a way, but it's not pretty: 好吧,如果确实需要,有一种方法,但这不是很漂亮:

var service = container.Resolve<IService>();
var meta = (IWcfChannelHolder) service;
var channel = (IClientChannel) meta.Channel;
var address = channel.RemoteAddress;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM