简体   繁体   English

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

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

I am trying to create a WCF service hostsed in windows service and I'm testing locally before I deploy to a server. 我试图创建Windows服务中托管的WCF服务,并且在部署到服务器之前在本地进行测试。

Created and installed the service ok and I can run the service just fine. 创建并安装服务正常,我可以正常运行该服务。

When I try to add a reference either though Visual studio or using WCFTestClient I get the following error. 当我尝试通过Visual Studio或使用WCFTestClient添加引用时,出现以下错误。

Error: Cannot obtain Metadata from http://localhost/ServiceModelSamples/service If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. 错误:无法从http:// localhost / ServiceModelSamples / service获取元数据如果这是您有权访问的Windows(R)Communication Foundation服务,请检查是否已在指定地址启用元数据发布。 For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error URI: http://localhost/ServiceModelSamples/service Metadata contains a reference that cannot be resolved:' http://localhost/ServiceModelSamples/service '. 有关启用元数据发布的帮助,请参阅MSDN文档, 网址http://go.microsoft.com/fwlink/?LinkId=65455。WS-MetadataExchange错误URI: http:// localhost / ServiceModelSamples / service元数据包含参考无法解决的问题:“ http:// localhost / ServiceModelSamples / service ”。 There was no endpoint listening at http://localhost/ServiceModelSamples/service that could accept the message. http:// localhost / ServiceModelSamples / service上没有侦听终结点的端点可以接受该消息。 This is often caused by an incorrect address or SOAP action. 这通常是由不正确的地址或SOAP操作引起的。 See InnerException, if present, for more details. 有关更多详细信息,请参见InnerException(如果存在)。 The remote server returned an error: (404) Not Found. 远程服务器返回错误:(404)找不到。 HTTP GET Error HTTP GET错误
URI: http://localhost/ServiceModelSamples/service There was an error downloading ' http://localhost/ServiceModelSamples/service '. URI: http:// localhost / ServiceModelSamples / service下载“ http:// localhost / ServiceModelSamples / service ”时出错。
The request failed with HTTP status 404: Not Found. 请求失败,HTTP状态为404:找不到。

here is my app.config 这是我的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>

As you can see its a slight modification to the tutorial found on msdn for hosting a WCF service in a Windows Service. 如您所见,它对msdn上的教程进行了少许修改,该教程用于在Windows Service中托管WCF服务。

I have tried reaserching this but haven't found much or most of the issues seem related to IIS hosting. 我已经尝试过重新设置此方法,但没有发现很多或大多数问题似乎与IIS托管有关。

UPDATE 更新

After adding the port number as suggested by venerik, the error has now changed to the following. 按照venerik的建议添加端口号后,该错误现在已更改为以下内容。

Error: Cannot obtain Metadata from http://localhost:8000/ServiceModelSamples/service If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. 错误:无法从http:// localhost:8000 / ServiceModelSamples / service获取元数据如果这是您有权访问的Windows(R)Communication Foundation服务,请检查是否已在指定地址启用元数据发布。 For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error URI: http://localhost:8000/ServiceModelSamples/service Metadata contains a reference that cannot be resolved: ' http://localhost:8000/ServiceModelSamples/service '. 有关启用元数据发布的帮助,请参阅MSDN文档, 网址http://go.microsoft.com/fwlink/?LinkId=65455。WS-MetadataExchange错误URI: http:// localhost:8000 / ServiceModelSamples / service元数据包含无法解析的引用:“ http:// localhost:8000 / ServiceModelSamples / service ”。 There was no endpoint listening at http://localhost:8000/ServiceModelSamples/service that could accept the message. 在可以接受该消息的http:// localhost:8000 / ServiceModelSamples / service上没有侦听任何终结点的端点。 This is often caused by an incorrect address or SOAP action. 这通常是由不正确的地址或SOAP操作引起的。 See InnerException, if present, for more details. 有关更多详细信息,请参见InnerException(如果存在)。 Unable to connect to the remote server No connection could be made because the target machine actively refused it 127.0.0.1:8000HTTP GET Error URI: http://localhost:8000/ServiceModelSamples/service There was an error downloading ' http://localhost:8000/ServiceModelSamples/service '. 无法连接到远程服务器无法建立连接,因为目标计算机主动拒绝它127.0.0.1:8000HTTP GET错误URI: http:// localhost:8000 / ServiceModelSamples / service下载' http:// localhost时出错:8000 / ServiceModelSamples / service Unable to connect to the remote server No connection could be made because the target machine actively refused it 127.0.0.1:8000 无法连接到远程服务器无法建立连接,因为目标计算机主动拒绝它127.0.0.1:8000

You should connect your client (like WcfTestClient) to http://localhost:8000/ServiceModelSamples/service . 您应该将客户端(例如WcfTestClient)连接到http://localhost:8000/ServiceModelSamples/service The error says you are trying to connect to http://localhost/ServiceModelSamples/service without the port, that is. 该错误表明您正尝试在没有端口的情况下连接到http://localhost/ServiceModelSamples/service

I assume you have IIS running at localhost? 我假设您在本地主机上运行IIS? That's why the error also says The remote server returned an error: (404) Not Found. 这就是为什么错误也显示The remote server returned an error: (404) Not Found. The IIS server is listening at port 80 and cannot find ServiceModelSamples/service and thus returns 404. IIS服务器正在侦听端口80,并且找不到ServiceModelSamples/service ,因此返回404。

The problem for me was the Service Name was not set in the service properties so I set this and also ensured the installer service name matched. 对我来说,问题是未在服务属性中设置“服务名称”,因此我对此进行了设置,并确保安装程序服务名称匹配。 Also set it to a LocalSystem Account. 还要将其设置为LocalSystem帐户。 Not sure if that had any affect but it was set as NetworkService 不确定是否有任何影响,但已将其设置为NetworkService

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

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