【问题标题】:WCF Only Add Service Reference in Same ProjectWCF 仅在同一项目中添加服务引用
【发布时间】:2014-08-19 04:08:43
【问题描述】:

我有一个 WCF 服务,如果我创建代理的项目(通过添加服务引用)与 WCF 服务在相同解决方案中,我可以为其创建代理.

但是,如果我尝试在与 WCF 服务(我确实在运行)不同的解决方案中的项目中添加服务引用,则无法找到端点。

这些消息谈论元数据,但我添加了以下暴露元数据的行为

<serviceMetadata httpGetEnabled="true" />

错误信息的详细信息是:

There was an error downloading 'http://localhost:8112/LTA/_vti_bin/ListData.svc/$metadata'.
The request failed with HTTP status 405: Method Not Allowed.
Metadata contains a reference that cannot be resolved: 'http://localhost:8112/LTA'.
There was no endpoint listening at http://localhost:8112/LTA that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
The remote server returned an error: (404) Not Found.
If the service is defined in the current solution, try building the solution and adding the service reference again.

有人知道问题出在哪里吗?整个 ServiceModel 元素是:

<system.serviceModel>
<services>
  <service name="WCFLicenceService.LicenceTrackerService">
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8112" />
      </baseAddresses>
    </host>
    <endpoint address="LTS" binding="basicHttpBinding" contract="WCFLicenceService.ILicenceTrackerService" />
    <endpoint 
      address="net.tcp://localhost:8113/LTS" 
      binding ="netTcpBinding" 
      contract="WCFLicenceService.ILicenceTrackerService" />
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior>
      <serviceDebug includeExceptionDetailInFaults="true" />
      <serviceMetadata httpGetEnabled="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<bindings>
  <basicHttpBinding>
    <binding maxReceivedMessageSize="2147483647" maxBufferSize="2147483647">
      <readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647" />
    </binding>
  </basicHttpBinding>
  <netTcpBinding>
    <binding maxReceivedMessageSize="2147483647" maxBufferSize="2147483647">
      <readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647"/>
    </binding>
  </netTcpBinding>
</bindings>
</system.serviceModel>

【问题讨论】:

    标签: wcf


    【解决方案1】:

    如您所见,服务引用是针对http://localhost:8112/LTA/_vti_bin/ListData.svc/$metadata 创建的,该http://localhost:8112/LTA/_vti_bin/ListData.svc/$metadata 必须是实时的。如果 Web 服务项目在同一个 Sln 中,VS IDE 可以通过在 IIS Express 等内置 Web 服务器上启动服务来为您完成技巧。如果服务项目位于另一个 sln 中,您将不得不在另一个 VS IDE 实例中运行该服务。

    对于大型项目,以及那些被其他 VS 解决方案中的许多其他项目使用的 Web 服务,最好不要使用服务引用方法,而是可以为每个服务创建一个客户端 API。客户端 API 可以分发到其他 .NET 项目。有关如何创建客户端 API 和各自优势的更多详细信息,请查看 WCF for the Real World, Not Hello World

    【讨论】:

    • 我不确定我是否没有说清楚,但我确实在其他解决方案中启动并运行了该服务。所以我不知道为什么客户端项目找不到服务,该服务正在本地主机的相关端口上侦听。
    • 我得到了 http 绑定工作。 ntetcp 不起作用,即使防火墙完全关闭。感谢您提供文章的链接。我一定会读的。
    • 当服务在 IDE 中运行时,您能否在 Web 浏览器中打开 localhost:8112/LTA/_vti_bin/ListData.svc/$metadatalocalhost:8112/LTA/_vti_bin/ListData.svc/?wsdl?例如,您在 VS IDE 1 中使用 IIS Express 运行服务,而 IDE 2 无法从 URL 读取 WSDL,而 Web 浏览器可以,我会感到非常惊讶。不过,我遵循给定链接中建议的做法,因此尽管在 WCF 编程的第 1 天我完成了您的路径。
    • 我将服务托管在控制台应用程序中。如果我去localhost:5112 获取http,我可以查看元数据。我仍然无法为 nettcpbinding 创建代理。不知道为什么。我会奖励有用的链接和好的提示的答案。
    • 所以现在很清楚了。 Web 服务描述语言的 WSDL 标准,nettcpbinding 不提供 svcutil 或其 API 创建代理类的 WSDL 是合理的,尽管 WCF 支持包括 Web 服务在内的各种类型的服务。并且生成的代理类可以用于与 Web 相关的绑定,例如 http 绑定和 net tcp 绑定等。
    猜你喜欢
    • 1970-01-01
    • 2012-10-27
    • 1970-01-01
    • 1970-01-01
    • 2015-12-14
    • 2012-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多