繁体   English   中英

Windows Service中托管的WCF服务上的404错误

[英]404 Errors on WCF service hosted in Windows Service

我试图创建Windows服务中托管的WCF服务,并且在部署到服务器之前在本地进行测试。

创建并安装服务正常,我可以正常运行该服务。

当我尝试通过Visual Studio或使用WCFTestClient添加引用时,出现以下错误。

错误:无法从http:// localhost / ServiceModelSamples / service获取元数据如果这是您有权访问的Windows(R)Communication Foundation服务,请检查是否已在指定地址启用元数据发布。 有关启用元数据发布的帮助,请参阅MSDN文档, 网址http://go.microsoft.com/fwlink/?LinkId=65455。WS-MetadataExchange错误URI: http:// localhost / ServiceModelSamples / service元数据包含参考无法解决的问题:“ http:// localhost / ServiceModelSamples / service ”。 http:// localhost / ServiceModelSamples / service上没有侦听终结点的端点可以接受该消息。 这通常是由不正确的地址或SOAP操作引起的。 有关更多详细信息,请参见InnerException(如果存在)。 远程服务器返回错误:(404)找不到。 HTTP GET错误
URI: http:// localhost / ServiceModelSamples / service下载“ http:// localhost / ServiceModelSamples / service ”时出错。
请求失败,HTTP状态为404:找不到。

这是我的app.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
  <service behaviorConfiguration="CalculatorServiceBehavior" name="Microsoft.ServiceModel.Samples.CalculatorService">
    <endpoint address="" binding="basicHttpBinding" contract="Microsoft.ServiceModel.Samples.ICalculator" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />        
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8000/ServiceModelSamples/service" />
      </baseAddresses>
    </host>
  </service>
</services>
<bindings>
</bindings>
<behaviors>
  <serviceBehaviors>
    <behavior name="CalculatorServiceBehavior">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>        
  </serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>

如您所见,它对msdn上的教程进行了少许修改,该教程用于在Windows Service中托管WCF服务。

我已经尝试过重新设置此方法,但没有发现很多或大多数问题似乎与IIS托管有关。

更新

按照venerik的建议添加端口号后,该错误现在已更改为以下内容。

错误:无法从http:// localhost:8000 / ServiceModelSamples / service获取元数据如果这是您有权访问的Windows(R)Communication Foundation服务,请检查是否已在指定地址启用元数据发布。 有关启用元数据发布的帮助,请参阅MSDN文档, 网址http://go.microsoft.com/fwlink/?LinkId=65455。WS-MetadataExchange错误URI: http:// localhost:8000 / ServiceModelSamples / service元数据包含无法解析的引用:“ http:// localhost:8000 / ServiceModelSamples / service ”。 在可以接受该消息的http:// localhost:8000 / ServiceModelSamples / service上没有侦听任何终结点的端点。 这通常是由不正确的地址或SOAP操作引起的。 有关更多详细信息,请参见InnerException(如果存在)。 无法连接到远程服务器无法建立连接,因为目标计算机主动拒绝它127.0.0.1:8000HTTP GET错误URI: http:// localhost:8000 / ServiceModelSamples / service下载' http:// localhost时出错:8000 / ServiceModelSamples / service 无法连接到远程服务器无法建立连接,因为目标计算机主动拒绝它127.0.0.1:8000

您应该将客户端(例如WcfTestClient)连接到http://localhost:8000/ServiceModelSamples/service 该错误表明您正尝试在没有端口的情况下连接到http://localhost/ServiceModelSamples/service

我假设您在本地主机上运行IIS? 这就是为什么错误也显示The remote server returned an error: (404) Not Found. IIS服务器正在侦听端口80,并且找不到ServiceModelSamples/service ,因此返回404。

对我来说,问题是未在服务属性中设置“服务名称”,因此我对此进行了设置,并确保安装程序服务名称匹配。 还要将其设置为LocalSystem帐户。 不确定是否有任何影响,但已将其设置为NetworkService

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM