本文介绍了ChannelFactory 在端点上没有地址,为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我创建 ChannelFactory 的新实例时:

When I create a new instance of a ChannelFactory:

var factory = new ChannelFactory<IMyService>();

并且我创建了一个新通道,我有一个异常,说端点的地址为空.

and that I create a new channel, I have an exception saying that the address of the Endpoint is null.

我在 web.config 中的配置如上所述,一切都应该如此(尤其是端点的地址).

My configuration inside my web.config is as mentioned and everything is as it is supposed to be (especially the address of the endpoint).

如果我创建一个新的 MyServiceClientBase,它会从我的频道工厂加载所有配置:

If I create a new MyServiceClientBase, it loads all the configuration from my channel factory:

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)

为什么?

推荐答案

我终于找到了答案.ChannelFactory 不会从您的 Web.Config/app.config 读取信息.ClientBase(然后与 ChannelFactory 一起使用)可以.

I finally found the answer. ChannelFactory doesn't read information from your Web.Config/app.config. ClientBase (which then work with a ChannelFactory) does.

这一切让我花了几个小时的工作,但我终于找到了一个合理的理由.

All this costed me a few hours of work but I finally found a valid reason.

:)

这篇关于ChannelFactory 在端点上没有地址,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-03 02:31