【问题标题】:Could not find default endpoint element that references contract in WCF在 WCF 中找不到引用合同的默认端点元素
【发布时间】:2015-07-01 23:15:53
【问题描述】:

我有 mvc web 项目,并且我添加了另一个空项目,其中包含更像存储库的所有服务。

所以我遇到了引发错误的问题,即使我在 Web.config 中添加了绑定,我也无法弄清楚原因。

错误:

在 ServiceModel 客户端配置部分中找不到引用合同“DataService.ISDService”的默认端点元素。这可能是因为找不到您的应用程序的配置文件,或者因为在客户端元素中找不到与此协定匹配的端点元素。

App.config:

<configuration>
    <system.serviceModel>
        <bindings>
            <wsHttpBinding>
                <binding name="SDEndPoint" />
            </wsHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://services.local.com/Api.svc/wsHttp"
                binding="wsHttpBinding" bindingConfiguration="SDEndPoint"
                contract="ImageService.ISDService" name="SDEndPoint">
                <identity>
                    <userPrincipalName value="nyc\pc" />
                </identity>
            </endpoint>
        </client>
    </system.serviceModel>
</configuration>

Web.config:

<client>
      <endpoint address="http://services.local.com/Api.svc/wsHttp" binding="wsHttpBinding" bindingConfiguration="SDEndPoint" contract="ImageService.ISDService" name="SDEndPoint">
        <identity>
          <userPrincipalName value="nyc\pc" />
        </identity>
      </endpoint>
</client>

我不知道哪里出错了。

【问题讨论】:

  • > 我有一个 mvc web 项目,并且我添加了另一个空项目,它包含所有服务,更像是存储库您是在使用它们还是将它们托管在新的空项目中?如果您托管它们,是否需要启动项目?
  • 您可以在网络浏览器中浏览到http://services.local.com/Api.svc/wsHttp 吗?如果有,你看到了什么?
  • 我已经将该项目引用到我的网络(dll)中,我的启动项目是网络
  • 您是否使用“存储库”来使用托管在其他地方的 WCF?
  • 是的,服务工作正常。我创建了一个测试项目,并且能够从测试中连接。

标签: c# .net asp.net-mvc wcf wcf-configuration


【解决方案1】:

您必须将所有内容移至 Web.config 才能使其正常工作,因为托管服务的是 Web 应用程序。

【讨论】:

  • 该服务托管在其他地方,我在我的存储库项目和网站中引用该服务,简单地调用作为 Web 项目一部分的存储库。
  • @CodeBox 无论您实际上是在谈论托管服务还是客户端,都是一样的。不幸的是,您不能将 WCF 配置拆分到多个库中。您需要在应用程序的 Web.config 中包含所有基于配置的 WCF 配置,因为这实际上将管理您的客户端并为其提供上下文。
【解决方案2】:

解决您的问题,调用项目需要具有相同的服务配置。只需将&lt;System.ServiecModel /&gt; 部分复制到您的网站Webconfig 中。此外,您可能需要在存储库中复制相同的设置。

【讨论】:

    猜你喜欢
    • 2013-06-27
    • 2012-01-09
    • 2014-07-25
    • 2023-03-12
    • 2010-11-28
    • 2014-09-14
    • 2011-10-20
    相关资源
    最近更新 更多