c#RESTful Webservice - 更改web.config后出现错误404

时间:2015-02-06 10:20:01

标签: c# asp.net web-services web-config

我正在使用C#开发一个带有.NET的Web服务。一切正常,但由于我更改了我的web.config文件,我从服务器报告404收到错误 - 找不到文件。 在服务的构造函数完成之后和调用服务操作之前发生异常。 如果我从web.config中删除服务部分,它将再次起作用。我需要允许更高的邮件大小,因为我想要进行一些文件传输,并且不想将文件(大多数在1到150MB之间作为zip)拆分成小于30kb的小块以使其工作。所以我需要提高允许的响应大小。 我不知道服务崩溃的原因,但我确定我的web.config有问题:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <connectionStrings>
    <add
      name="MyDSNName"
      connectionString="MyConnectString"
  />
  </connectionStrings>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
    <!--
      LogLevel DefaultValue: E_ALL, ^E_NOTE, ^E_HINT, ^E_INFO, ^E_TRACE
      Represents: E_ALL, without E_NOTE, E_HINT, E_INFO and E_TRACE

      Avaiable:                  E_ERROR, E_WARNING, E_DEBUG, E_TRACE, 
                                 E_HINT, E_INFO, E_NOTE, E_SYSTEM, E_BOOT, E_ALL

      Development Value:          E_ALL, ^E_HINT, ^E_INFO
      Production Value:           E_SYSTEM, E_ERROR, E_WARNING, E_HINT
    -->
    <add key="loglevel" value="E_ALL"/>
  </appSettings>
  <system.web>
    <compilation debug="true" optimizeCompilations="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" maxRequestLength="2147483647" 
          maxQueryStringLength="2097151"/>
  </system.web>
  <system.serviceModel>
    <bindings>
      <webHttpBinding>
        <binding name="UpdateServiceCfg" receiveTimeout="00:10:00" 
           sendTimeout="00:10:00" openTimeout="00:10:00" 
          closeTimeout="00:10:00" maxReceivedMessageSize="10485760" 
          transferMode="Streamed">
          <security mode="None"/>
          <readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647" 
           maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" 
           maxDepth="2147483647" />
        </binding>
      </webHttpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="UpdateServiceBehavior" name="MyApp.UpdateService">
        <endpoint address="" behaviorConfiguration="web" binding="webHttpBinding"
          bindingConfiguration="UpdateServiceCfg" contract="MyApp.IUpdateService" />
        <host>
          <timeouts closeTimeout="00:10:00" />
        </host>
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="web">
          <webHttp helpEnabled="false" faultExceptionEnabled="true" />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="UpdateServiceBehavior">
          <serviceMetadata httpGetEnabled="false" httpsGetEnabled="false" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https"/>
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" 
             multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <directoryBrowse enabled="true"/>
  </system.webServer>
</configuration>

有人能给我一些解决问题的提示吗?

提前致谢。

1 个答案:

答案 0 :(得分:0)

将webHttpBinding标记重命名为basicHttpBinding使其工作。 :)