简体   繁体   English

WCF无法使用给定的端点名称创建通道工厂

[英]WCF Cannot create channel factory with given endpoint name

I would like to create a channel factory for my self-hosted service. 我想为我的自托管服务创建一个渠道工厂。 Here is my App.config file: 这是我的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>

Here is how I host the service 这是我托管服务的方式

host = new ServiceHost(typeof (Service.TexasHoldemService));
host.Open()

var factory = new ChannelFactory<ITexasHoldemService>("TexasHoldem");

However, I am getting a an exception like this: 但是,我遇到了这样的异常:

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.

I also tried with setting address in ChannelFactory constructor as: 我也尝试在ChannelFactory构造函数中将地址设置为:

http://localhost/TexasHoldem
http://localhost/Service.TexasHoldemService/TexasHoldem
net.tcp://localhost/TexasHoldem
net.tcp://localhost/Service.TexasHoldemService/TexasHoldem

And none of the above works ;/ 而且以上都不是; /

You need to add an <endpoint> under a <client> element to be able to call it from ChannelFactory : 您需要在<client>元素下添加一个<endpoint> ,以便能够从ChannelFactory进行调用:

Add the following code under <system.serviceModel> : <system.serviceModel>下添加以下代码:

  <client>
    <endpoint address="net.tcp://localhost:8090/TexasHoldem" binding="netTcpBinding" bindingConfiguration="" contract="Service.ITexasHoldemService" name="TexasHoldem">
    </endpoint>
  </client>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM