.net - ChannelFactory 在端点上没有地址,为什么?

标签 .net wcf configuration c#-3.0

当我创建 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/

相关文章:

c# - 元组必须包含至少两个元素

.net - 将文件上传到 WCF 3.5 服务

WCF 自定义 Http 代理身份验证

configuration - 您如何处理独立应用程序的密码或凭据?

c - 如何将 SOCKET (HANDLE) 从非托管 C 程序传递到 .NET 子进程?

c# - 在 .NET 中使用 volatile 进行线程间的单向通信

.net - 确定一个类使用多少内存?

c# - WCF 服务引用使用 XmlSerializer 创建临时动态程序集

java - Hadoop:作业显示在作业浏览器中,但无法通过 api 访问 JobStatus

deployment - 在 SSRS 中为不同的配置使用不同的数据源