【问题标题】:Simplest Console Hosted WCF Service generates a 404 when browse to it最简单的控制台托管 WCF 服务在浏览到它时会生成 404
【发布时间】:2016-12-21 05:52:18
【问题描述】:

我有一个非常简单的基于控制台的主机,用于简单的 WCF 服务。该服务的应用配置是:

<system.serviceModel>
    <services>
      <service name="MagicEightBallServiceLib.MagicEightBallService"
               behaviorConfiguration="EightBallServiceMEXBehavior">
        <endpoint address=""
                  binding = "basicHttpBinding"
                  contract = "MagicEightBallServiceLib.IEightBall" />
        <!-- Enable the MEX endpoint-->
      <endpoint address="mex"
                binding ="mexHttpBinding"
                contract ="IMetadataExchange" />
      <!--Need to add this so MEX knows the address of our service -->
      <host>
        <baseAddresses>
          <add baseAddress="http://localhost:8080/MagicEightBallService"/>
        </baseAddresses>
      </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="EightBallServiceMEXBehavior">
          <serviceMetadata httpGetEnabled="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

主机程序显示其完美运行: ** 基于控制台的 WCF 主机 *

***** Host Info ******
Address: http://localhost:8080/MagicEightBallService
Binding: BasicHttpBinding
Contract: IEightBall

Address: http://localhost:8080/MagicEightBallService/mex
Binding: MetadataExchangeHttpBinding
Contract: IMetadataExchange

**************************************************
The service is ready

当我尝试浏览或生成代理时,我得到: HTTP 错误 404.0 - 未找到

我不知道出了什么问题。没有比这更简单的了!

【问题讨论】:

    标签: wcf http-status-code-404


    【解决方案1】:

    我在阅读 Troelsen 的书时遇到了同样的问题,但在网上找不到任何答案。无论如何,问题似乎出在 MagicEightBallLib 的项目类型中。 Troelsen 建议您创建一个 Visual C# -> Windows -> 类库项目,但他没有解释您需要进行哪些修改才能使其正常工作。如果您改用 Visual C# -> WCF -> WCF 服务库项目,它将自动启动 WcfTestClient.exe,并在项目的首选项中添加名为“WCF 选项”的新选项卡。我试图比较这两种项目的 .csproj 文件之间的差异,但数量太多了。 所以解决方案是从 WCF 服务库项目类型开始而不是类库,并调整接口和类的名称,使其符合书中的内容。

    如果有人知道 .csproj 文件的哪些特定部分负责启用此功能,我非常想听听。

    希望这会有所帮助。

    【讨论】:

      【解决方案2】:

      不要使用 localhost:8080,而是使用 127.0.0.1:8080。这就是我如何让示例在我的 Windows 10 机器上运行。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-07-02
        • 2012-04-07
        • 1970-01-01
        相关资源
        最近更新 更多