[英]WCF ChannelFactory.CreateChannel()
Why is it I'm able to do this: 为什么我能够这样做:
var _channel = new ChannelFactory<T>("bindingname").CreateChannel();
But not this 但不是这个
var _channelFactory = new ChannelFactory<T>("bindingname");
var _channel = _channelFactory.CreateChannel();
The 2nd snippet complains that I need to pass in an EndPointAddress
in CreateChannel()
whereas the 1st doesn't. 第二个片段抱怨我需要在
CreateChannel()
传递一个EndPointAddress
,而第一个则没有。
Aren't the 2 snippets essentially the same? 这两个片段基本上不一样吗?
It might be because var _channelFactory = new ChannelFactory<T>("bindingname");
这可能是因为
var _channelFactory = new ChannelFactory<T>("bindingname");
is resolving _channelFactory to IChannelFactory<T>
instead of ChannelFactory<T>
. 正在将_channelFactory解析为
IChannelFactory<T>
而不是ChannelFactory<T>
。
Try 尝试
ChannelFactory<T> _channelFactory = new ChannelFactory<T>("bindingname");
var _channel = _channelFactory.CreateChannel();
ChannelFactory<T> has a CreateChannel() method that takes no parameters. ChannelFactory <T>有一个不带参数的CreateChannel()方法。 IChannelFactory<T> does not have a CreateChannel() method that takes no parameters.
IChannelFactory <T>没有不带参数的CreateChannel()方法。
Looking at the signature for the constructors for ChannelFactory, the only one that takes a single string as an input is asking for an endpointConfigurationName - not a binding name. 查看ChannelFactory的构造函数的签名,唯一一个将单个字符串作为输入的是请求endpointConfigurationName - 而不是绑定名称。 Could this be the root of your problem?
这可能是你问题的根源吗? You may be constructing the ChannelFactory incorrectly?
您可能错误地构建了ChannelFactory? See below:-
见下文:-
public ChannelFactory();
public ChannelFactory(Binding binding);
public ChannelFactory(ServiceEndpoint endpoint);
public ChannelFactory(string endpointConfigurationName);
protected ChannelFactory(Type channelType);
public ChannelFactory(Binding binding, EndpointAddress remoteAddress);
public ChannelFactory(Binding binding, string remoteAddress);
public ChannelFactory(string endpointConfigurationName, EndpointAddress remoteAddress);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.