【问题标题】:Cant connect to WCF Service. Missing EndPointElemt无法连接到 WCF 服务。缺少端点元素
【发布时间】:2015-05-30 16:05:53
【问题描述】:

我正在尝试创建自己的 WCF 服务和客户端。我使用以下 app.config 设置创建了我的服务:

    <system.serviceModel>
    <services>
        <service name="Interface.MyWCFService">
            <endpoint address="http://localhost:9999/MyService" binding="basicHttpBinding"
                bindingConfiguration="" name="MyServiceEndpoint" contract="Interface.IMyWCFService" />
        </service>
    </services>
</system.serviceModel>

服务无异常启动。

我的客户应该连接到这个服务。他的 app.config 就是这个:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
   <system.serviceModel>
        <client>
             <endpoint address="http://localhost:9999/MyService" binding="basicHttpBinding"
                  bindingConfiguration="" contract="Interface.IMyWCFService"
                  name="MyServiceEndpoint" kind="" endpointConfiguration="" />
        </client>
    </system.serviceModel>
</configuration>

在 c# 代码中,我尝试使用以下代码在 client.cs 中创建一个通道工厂:

 ChannelFactory<IMyWCFService> channelFactory = new ChannelFactory<IMyWCFService>("MyServiceEndpoint", new EndpointAddress("http://localhost:9999/MyService"));

        IMyWCFService proxy = channelFactory.CreateChannel();

这不起作用。每次我尝试启动程序时,都会出现以下异常:

没有名称为“MyServiceEndpoint”和合同的 Endpointelement “Interface.IMyWCFService”位于 ServiceModel-Client 配置部分。

我希望你能帮助我。

【问题讨论】:

    标签: c# wcf channelfactory


    【解决方案1】:

    这就是我配置服务的方式:

      <service name="foo.bar.BlaService">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost/BlaService" />
          </baseAddresses>
        </host>
        <endpoint address="" binding="basicHttpBinding" contract="foo.bar.IBlaService" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    

    这里是客户:

    <client>
      <endpoint name="BlaService" address="http://localhost/BlaService" binding="basicHttpBinding" contract="foo.bar.IBlaService" />
    </client>
    

    【讨论】:

    • 错误是指端点,而不是服务。 OP 的服务配置看起来是正确的,但错误在客户端,而不是服务。
    • 好的,既然错误是本地化到客户端的,有什么想法吗?
    • @Christoph,你试过我的建议了吗?在 WCF 中,某些设置必须在服务器和客户端之间同步...
    • 嘿,根据您的设置,服务不再启动。打开服务主机时还有一个异常。该服务没有应用程序端点
    • @Christoph,刚刚描述了我通常的做法。这有帮助吗?我可以使用这些设置创建一个频道...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-02-22
    • 2015-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    相关资源
    最近更新 更多