当我创建 ChannelFactory 的新实例时:
var factory = new ChannelFactory<IMyService>();
并且我创建了一个新 channel ,但有一个异常,说端点的地址为空。
我的 web.config 中的配置如上所述,一切都按预期进行(尤其是端点的地址)。
如果我创建一个新的 MyServiceClientBase,它会从我的 channel 工厂加载所有配置:
var factoryWithClientBase = new MyServiceClientBase().ChannelFactory;
Console.WriteLine(factoryWithClientBase.Endpoint.Address); //output the configuration inside the web.config
var factoryWithChannelFactory = new ChannelFactory<IMyService>();
Console.WriteLine(factoryWithChannelFactory.Endpoint.Address); //output nothing (null)
为什么?
最佳答案
如果您在 Web.Config 中为端点提供这样的名称,它会起作用吗:
<endpoint address="http://localhost:2000/MyService/" binding="wsHttpBinding"
behaviorConfiguration="wsHttpBehaviour" contract="IService"
name="MyWsHttpEndpoint" />
并使用 ChannelFactory 创建 channel ,如下所示:
var factory = new ChannelFactory<IMyService>("MyWsHttpEndpoint");
关于.net - ChannelFactory 在端点上没有地址,为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/297431/