为什么我的 ChannelFactory 看不到我的端点配置? [英] Why doesn't my ChannelFactory see my endpoint configuration?
问题描述
我一直在关注 Miguel Castro 关于 WCF 的优秀文章这里,一切正常很好,除了我有以下代码
I've been following Miguel Castro's excellent article on WCF here and it's all working nicely, except that I have the following code
public AdminClient()
{
ChannelFactory<IProductAdmin> factory = new ChannelFactory<IProductAdmin>();
productAdminChannel = factory.CreateChannel();
}
在我的 app.config 文件中,我有以下配置:
In my app.config file, I have the following configuration:
<system.serviceModel>
<client>
<endpoint address="net.tcp://localhost:8002/ProductBrowser"
binding="netTcpBinding"
contract="Contracts.IProductAdmin" />
</client>
</system.serviceModel>
但是,当我运行 AdminClient 的构造函数时,我收到一个异常,指出端点未定义.但是,如果我更改我的配置以给端点命名,然后按如下方式创建工厂,它就可以工作.
But, when I run the constructor for AdminClient I get an exception saying that the endpoint isn't defined. However, if I change my configuration to give the endpoint a name, and then create the factory as follows, it works.
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 中的文档没有多大帮助...
I'd love an explanation for this. The documentation in MSDN isn't much help...
推荐答案
使用*"来使用第一个符合条件的端点.
Use "*" to use the first qualifying endpoint.
public AdminClient()
{
ChannelFactory<IProductAdmin> factory
= new ChannelFactory<IProductAdmin>("*");
productAdminChannel = factory.CreateChannel();
}
这篇关于为什么我的 ChannelFactory 看不到我的端点配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!