简体   繁体   English

如何获取特定WCF服务正在使用的绑定

[英]How to get the binding that a particular WCF service is using

Is there a way to get the binding that a WCF service is using from the object instance of the service class itself? 有没有办法从服务类本身的对象实例中获取WCF服务正在使用的绑定?

I'm currently debugging a WCF service and have changed the client bindings and want to see if they are the one's that are being applied to the proxy class that represents the service interface. 我目前正在调试WCF服务,并更改了客户端绑定,并想查看它们是否是应用于代表服务接口的代理类的绑定。

As an aside the proxy class is being created using the ChannelFactory<IMyWCFService>.CreateChannel() method. ChannelFactory<IMyWCFService>.CreateChannel()正在使用ChannelFactory<IMyWCFService>.CreateChannel()方法创建代理类。 However as this is a MVC web application and the method call is done via Dependency Injection. 但是,由于这是MVC Web应用程序,因此方法调用是通过依赖注入完成的。 So the proxy object is injected into my code. 因此,代理对象被注入到我的代码中。

So just to be clear at the point in the code where I am using the proxy object I don't have access to original ChannelFactory. 因此,为了清楚起见,在代码中我使用代理对象时,我无权访问原始ChannelFactory。 I know the binding that the ChannelFactory is using as it is set whilst configuring the dependency injection container within the Global.asax.cs class. 我知道ChannelFactory在设置Global.asax.cs类中的依赖项注入容器时正在使用的绑定。 However as we are using dependency injection there is no guarantee that the ChannelFactory or indeed binding defined in the Global.asax.cs is the one being used to create the proxy object as it might have been changed by some other code. 但是,由于我们使用依赖项注入,因此不能保证ChannelFactory或Global.asax.cs中定义的绑定实际上是用于创建代理对象的对象,因为它可能已被其他代码更改。 The issue I am having is we are changing explicitly setting values on the binding used in the Global.asax.cs class but this settings aren't taking affect which makes suspicous that another binding is being used. 我遇到的问题是,我们正在Global.asax.cs类中使用的绑定上显式更改设置值,但是此设置未生效,这使人们怀疑正在使用其他绑定。

You can get binding from Endpoint object of service: 您可以从Endpoint服务对象获取绑定:

var service = new Service1Client();
Binding binding = service.Endpoint.Binding;
Console.WriteLine(binding);

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

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