我一直在关注 Miguel Castro 关于 WCF 的优秀文章 here一切都运行良好,除了我有以下代码
public AdminClient()
{
ChannelFactory<IProductAdmin> factory = new ChannelFactory<IProductAdmin>();
productAdminChannel = factory.CreateChannel();
}
在我的 app.config 文件中,我有以下配置:
<system.serviceModel>
<client>
<endpoint address="net.tcp://localhost:8002/ProductBrowser"
binding="netTcpBinding"
contract="Contracts.IProductAdmin" />
</client>
</system.serviceModel>
但是,当我运行 AdminClient 的构造函数时,我收到一个异常,指出端点未定义。但是,如果我更改配置以给端点命名,然后按如下方式创建工厂,则它可以工作。
public AdminClient()
{
var fac = new ChannelFactory<IProductAdmin>("admin");
productAdminChannel = fac.CreateChannel();
}
<小时/>
<system.serviceModel>
<client>
<endpoint name="admin"
address="net.tcp://localhost:8002/ProductBrowser"
binding="netTcpBinding"
contract="Contracts.IProductAdmin" />
</client>
</system.serviceModel>
我希望对此有一个解释。 MSDN 中的文档没有太大帮助...
最佳答案
使用“*”使用第一个合格端点。
public AdminClient()
{
ChannelFactory<IProductAdmin> factory
= new ChannelFactory<IProductAdmin>("*");
productAdminChannel = factory.CreateChannel();
}
关于wcf - 为什么我的 ChannelFactory 看不到我的端点配置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/426041/