最简单的控制台托管WCF服务在浏览时生成404

时间:2012-12-14 18:39:39

标签: wcf http-status-code-404

我有一个非常简单的基于控制台的主机,用于简单的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 - 未找到

我无法弄清楚出了什么问题。你不能比这更简单!

2 个答案:

答案 0 :(得分:0)

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

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

希望这有帮助。

答案 1 :(得分:0)

而不是使用localhost:8080使用127.0.0.1:8080。这就是我在Windows 10机器上运行示例的方法。