IIS 休息服务从外部服务器给出 404 错误



我安装了一个提供 REST 服务的 WCF 服务。在我的开发机器上,它工作正常,但我在部署时遇到了问题。出于安全原因,实际服务安装在防火墙后面的一台服务器上。对该服务器的访问来自外部服务器,该服务器提供前端,通过防火墙传递呼叫并将答案返回给客户端。两台服务器都运行 IIS 7。我的 web.config 看起来像这样:

<?xml version="1.0"?>
<configuration>
  <configSections>
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
  <section name="TalLimoService.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<connectionStrings>
  ...
</connectionStrings>
<appSettings>
  ...
</appSettings>
<system.web>
  <compilation targetFramework="4.0"/>
  <httpRuntime requestPathInvalidCharacters="&lt;,&gt;,%,&amp;,,?"/>
</system.web>
<system.serviceModel>
  <bindings />
  <client />
  <services>
   <service name="SomethingService.SomethingService" behaviorConfiguration="ServiceBehavior">
     <!--Service Endpoints-->
     <!-- Unless fully qualified, address is relative to base address supplied above-->
     <endpoint address="" binding="webHttpBinding" contract="TalLimoService.ITalLimoService" behaviorConfiguration="web" />
   </service>
  </services>
  <behaviors>
    <serviceBehaviors>
      <behavior name="ServiceBehavior">
      <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="false"/>
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="web">
      <webHttp/>
    </behavior>
  </endpointBehaviors>
</behaviors>
<protocolMapping>
  <add binding="basicHttpsBinding" scheme="https"/>
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true"/>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <!--
    To browse web app root directory during debugging, set the value below to true.
    Set to false before deployment to avoid disclosing web app folder information.
    -->
  <directoryBrowse enabled="true"/>
</system.webServer>
<system.diagnostics>
...
</system.diagnostics>
<applicationSettings>
...
</applicationSettings>
</configuration>

当我从内部服务器浏览服务时,我得到适当的响应。 当我从互联网或外部服务器浏览时,出现 404 错误。网站日志文件记录了两次尝试,包括来自内部服务器的 200 代码和来自外部服务器的 404 代码。 例如:

2014-11-18 ... 192.0.0.1 GET /SomethingService/SomethingService.svc/SomeFunction/Parameter - 80 127.0.0.1 Mozilla/5.0+... 200 0 0 124
2014-11-18 ... 192.168.1.6 GET /SomethingService/SomethingService.svc/SomeFunction/Parameter - 80  212.143.135.6 404 0 2 218

web.config 文件中定义的跟踪日志记录来自内部调用的服务响应,但跟踪日志中没有来自外部服务器的调用的记录。有人可以建议可能发生的事情吗?或者提供有关如何调试的线索?

事实证明,我没有足够仔细地查看日志。实际上,来自外部服务器的调用如下所示:

GET /SomethingService/SomethingService.svcSomeFunction/Parameter - 80  212.143.135.6 404 0 2 218

换句话说,缺少将 URL 与函数模板分隔的斜杠标记。 由于 URL 是从外部服务器的配置文件中读取的,因此我所要做的就是将斜杠添加到配置文件中。 这就解释了为什么调用从内部服务器工作,我在浏览器地址栏中键入了 URL 和函数名称。

故事的寓意是:非常仔细地比较字符串,如果可能的话,以编程方式进行。计算机太愚蠢了,不能错过差异。

相关内容

最新更新