我一直在关注米格尔·卡斯特罗对WCF优秀文章在这里,这一切都工作很好,但我有以下代码
public AdminClient()
{
ChannelFactory<IProductAdmin> factory = new ChannelFactory<IProductAdmin>();
productAdminChannel = factory.CreateChannel();
}
Run Code Online (Sandbox Code Playgroud)
在我的app.config文件中,我有以下配置:
<system.serviceModel>
<client>
<endpoint address="net.tcp://localhost:8002/ProductBrowser"
binding="netTcpBinding"
contract="Contracts.IProductAdmin" />
</client>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)
但是,当我运行AdminClient的构造函数时,我得到一个异常,说明端点没有定义.但是,如果我更改配置以给端点命名,然后按如下方式创建工厂,则它可以工作.
public AdminClient()
{
var fac = new ChannelFactory<IProductAdmin>("admin");
productAdminChannel = fac.CreateChannel();
}
Run Code Online (Sandbox Code Playgroud)
<system.serviceModel>
<client>
<endpoint name="admin"
address="net.tcp://localhost:8002/ProductBrowser"
binding="netTcpBinding"
contract="Contracts.IProductAdmin" />
</client>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)
我喜欢这个的解释.MSDN中的文档没有太大帮助......
Sky*_*ers 62
使用"*"来使用第一个合格端点.
public AdminClient()
{
ChannelFactory<IProductAdmin> factory
= new ChannelFactory<IProductAdmin>("*");
productAdminChannel = factory.CreateChannel();
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
20536 次 |
最近记录: |