【问题标题】:WCF Configuration for Endpoint in Another Project另一个项目中端点的 WCF 配置
【发布时间】:2011-07-14 14:35:51
【问题描述】:

我在一个解决方案中有两个项目。一个项目,我们称之为 MainProject,变成了一个可执行文件。另一个项目,我们称之为 ControlsProject,包含UserControl,并在 MainProject 中被引用(和使用)。 ControlsProject 也有一个 WCF 服务参考。

关于这个配置我有两个问题:

  1. 我可以将 WCF 配置从 ControlsProject 复制到 MainProject(我不相信我可以按照“How to include Web reference endpoint configuration in another project”)
  2. 在 ControlsProject 配置中,合同没有完全限定的命名空间,而是有一个名称,例如“ServiceName.IServiceInterfaceName”。合同名称应该是什么,因为 ControlsProject 输出将是位于 MainProject 的 bin 文件夹中的文件?

我尝试只复制配置,但收到异常:“Could not find default endpoint element that references contract 'MyService.IMyService' 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 contract could be found in the client element.”当我复制配置时,我将接口的名称完全限定为ControlsProject.MyService.IMyService

感谢您提供的任何帮助!

更新 (2011 年 7 月 14 日下午 5:28 EST)

这是来自我的客户端 app.config 的 sn-p:

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_IStatService" closeTimeout="00:01:00"
                openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                useDefaultWebProxy="true">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <security mode="None">
                    <transport clientCredentialType="None" proxyCredentialType="None"
                        realm="" />
                    <message clientCredentialType="UserName" algorithmSuite="Default" />
                </security>
            </binding>
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://intranet/StatService.svc"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IStatService"
            contract="StatService.IStatService" name="BasicHttpBinding_IStatService" />
    </client>
</system.serviceModel>

这是我的网络服务 web.config 中的 sn-p:

<system.serviceModel>
  <behaviors>
    <serviceBehaviors>
      <behavior name="">
        <serviceMetadata httpGetEnabled="true" />
        <serviceDebug includeExceptionDetailInFaults="true" />
      </behavior>
    </serviceBehaviors>
  </behaviors>
  <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>

【问题讨论】:

    标签: wcf wcf-binding wcf-configuration wcf-endpoint


    【解决方案1】:

    任何时候您看到“无法找到某某合约的默认端点元素”,那么您的实际合约(接口)就没有在 app.config 文件中正确引用。转到控件项目中的接口合同,仔细检查它所在的命名空间,您需要确切的命名空间。“接口名称”作为 app.config 中的合同元素。您还需要确保您的 service name=Namespace.MyService 是正确的命名空间和类。一种知道您是否正确的简短方法(仅当您有 resharper 时),在您声明服务名称 = 的 appconfig 中,将光标放在服务名称和命名空间上,然后按 F12,如果它没有带您到任何地方您正在引用一个不存在的命名空间和类,对于 contract=,如果您在该合同上按 F12 并且它没有将您带到那里,则它没有被正确引用(可能拼写错误)。

    【讨论】:

    • 因此,如果我将其更改回合同中列出的内容,我的项目会引发以下异常:“接收到myadress/MyService.svc 的 HTTP 响应时发生错误。这可能是由于服务端点绑定不使用 HTTP 协议。这也可能是由于 HTTP 请求上下文被服务器中止(可能是由于服务关闭)。有关更多详细信息,请参阅服务器日志。再说一次,我要跨项目。
    • 无论如何您可以发布 app.config 中的内容吗?我一直在使用 WCF 解决方案来处理项目,通常我在它自己的库中建立合同和服务,然后让另一个项目/应用程序托管该服务,另一个项目/应用程序使用该服务。这些错误对我来说非常熟悉,每次我在 app.config 中都有问题
    • 我正在使用默认设置,您很快就会在上面看到。
    • 我已经发布了这些配置设置。
    • 好的,从我所见,在客户端端点中不需要 name=。此外,有关您在 web.config 部分中托管的服务的信息在哪里?我只看到你发布了行为部分。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-05-29
    • 1970-01-01
    • 1970-01-01
    • 2018-02-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多