简体   繁体   中英

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:

<?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:

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 :

Add the following code under <system.serviceModel> :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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