IIS Rest服务从外部服务器提供404错误

时间:2014-11-18 15:54:19

标签: web-services wcf iis

我已经安装了一个提供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文件中定义的跟踪日志记录来自内部调用的服务响应,但是来自外部服务器的调用的跟踪日志中没有记录。有人可以建议可能发生的事情吗?或者提供如何调试的线索?

1 个答案:

答案 0 :(得分:1)

事实证明,我没有仔细查看日志。实际上,来自外部服务器的调用看起来像这样:

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

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

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