我想为自托管服务创建一个频道工厂。这是我的App.config文件:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="mexBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="mexBehavior" name="Service.TexasHoldemService">
<endpoint address="TexasHoldem" binding="netTcpBinding" bindingConfiguration=""
contract="Service.ITexasHoldemService" name="TexasHoldem"/>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080" />
<add baseAddress="net.tcp://localhost:8090" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
</configuration>
以下是我托管服务的方式
host = new ServiceHost(typeof (Service.TexasHoldemService));
host.Open()
var factory = new ChannelFactory<ITexasHoldemService>("TexasHoldem");
但是,我得到一个像这样的例外:
An unhandled exception of type 'System.InvalidOperationException' occurred in System.ServiceModel.dll
Could not find endpoint element with name 'TexasHoldem' and contract 'Service.ITexasHoldemService'
in the ServiceModel client configuration section. This might be because no configuration file was
found for your application, or because no endpoint element matching this name could be
found in the client element.
我也试过在ChannelFactory构造函数中设置地址为:
http://localhost/TexasHoldem
http://localhost/Service.TexasHoldemService/TexasHoldem
net.tcp://localhost/TexasHoldem
net.tcp://localhost/Service.TexasHoldemService/TexasHoldem
以上都不起作用; /
答案 0 :(得分:1)
您需要在<endpoint>
元素下添加<client>
才能从ChannelFactory
调用它:
在<system.serviceModel>
下添加以下代码:
<client>
<endpoint address="net.tcp://localhost:8090/TexasHoldem" binding="netTcpBinding" bindingConfiguration="" contract="Service.ITexasHoldemService" name="TexasHoldem">
</endpoint>
</client>