简体   繁体   中英

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:

_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:

 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?

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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