【问题标题】:Could not find default endpoint element ... in WCF Client在 WCF 客户端中找不到默认端点元素...
【发布时间】:2010-06-04 01:13:43
【问题描述】:

我在引用合同程序集的服务解决方案中创建了一个代理库类,并将库(合同、代理)复制到另一个解决方案文件夹。然后在另一个类库中引用了 Proxy、Contract 和 System.ServiceModel 库,我需要使用其中包含的一个方法,并在库中添加 App.Config。

服务托管在 Windows 窗体应用程序中。客户端是从窗体应用程序调用的类库。我还没有在窗体项目中创建 App.Config。实际上,Windows 窗体项目在库中加载了一个控件,并且该控件在我需要使用服务方法的地方加载了库。所以我认为我应该只在最新的程序集中引用(合同和代理),因为我不会在其他任何地方使用它。

但我不断收到此错误:

找不到默认端点 引用合约的元素 'Sign.Contracts.ISignDocument' 在 ServiceModel 客户端配置 部分。这可能是因为没有 为您找到了配置文件 应用程序,或者因为没有端点 与本合同相匹配的元素可以 可以在客户端元素中找到。

libray 中的 App.Config 调用代理:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <services>
      <client>
        <endpoint
          address="http://localhost:8731/SignHere"
          binding="basicHttpBinding"
          contract="Sign.Contracts.ISignDocument" />
      </client>
    </services>
  </system.serviceModel>
</configuration>

服务主机中的App.Config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <services>
      <service name="Sign.Service.SignDocumentService">
        <endpoint 
          address="http://localhost:8731/SignHere" 
          binding="basicHttpBinding" 
          contract="Sign.Contracts.ISignDocument" />
      </service>
    </services>
  </system.serviceModel>
</configuration>

代理类:

namespace Sign.Proxies
{
    public class Proxy : ClientBase<ISignDocument>, ISignDocument
    {
        public string SignDocument(string document)
        {
            return Channel.SignDocument(document);
        }
    }
}

合约类:

namespace Sign.Contracts
{
    [ServiceContract]
    public interface ISignDocument
    {
        [OperationContract]
        string SignDocument(string document);
    }
}

有什么想法吗?

【问题讨论】:

  • 要格式化代码或 XML,请在编辑器中选择它并按 Control-K。

标签: c# winforms wcf


【解决方案1】:

任何程序都只有一个配置文件。在您的情况下,这是 Winforms 程序的 app.config,在构建程序时将其复制到 programName.exe.config。

任何 WCF 配置都必须在该文件中。你的图书馆有一个 app.config 的事实并不重要。需要从库的app.config中复制相关配置项,并与Winforms应用的app.config合并。

【讨论】:

  • 在 winform 项目中添加了一个 App.Config 文件,我得到了同样的错误。
  • 这不是问题。您需要将 WCF 配置从库的 app.config 复制到 Winforms 应用程序的 app.config 中。
  • 是的,对不起,这就是我的意思,我在 winforms 应用程序中创建了一个 App.Config 文件并复制了内容。
【解决方案2】:

doooh...客户端 app.config 中没有客户端端点信息的父元素。

【讨论】:

    猜你喜欢
    • 2014-10-16
    • 1970-01-01
    • 1970-01-01
    • 2010-09-26
    • 2011-08-31
    • 2011-04-10
    • 1970-01-01
    • 2018-07-09
    • 2015-07-01
    相关资源
    最近更新 更多