相关疑难解决方法(0)

为什么我的ChannelFactory没有看到我的端点配置?

我一直在关注米格尔·卡斯特罗对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中的文档没有太大帮助......

wcf

48
推荐指数
1
解决办法
2万
查看次数

标签 统计

wcf ×1