Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WCF-大型文件上载-(413)请求实体太大_C#_Wcf - Fatal编程技术网

C# WCF-大型文件上载-(413)请求实体太大

C# WCF-大型文件上载-(413)请求实体太大,c#,wcf,C#,Wcf,有人能看看我的新密码吗?我被这个虫子缠住了三天,它快把我逼疯了 我正在尝试上载WCF文件,但未上载大文件 我得到了这个错误:“远程服务器返回了一个意外的响应:(413)请求实体太大。” 我的项目由三部分组成: WCF服务 使用服务的用户控件 使用用户控件的网站 这是我的服务we.config: <system.serviceModel> <services> <service name="AttachmentService" behaviorC

有人能看看我的新密码吗?我被这个虫子缠住了三天,它快把我逼疯了

我正在尝试上载WCF文件,但未上载大文件

我得到了这个错误:“远程服务器返回了一个意外的响应:(413)请求实体太大。”

我的项目由三部分组成:

  • WCF服务

  • 使用服务的用户控件

  • 使用用户控件的网站

  • 这是我的服务we.config:

    <system.serviceModel>
    
        <services>
          <service name="AttachmentService" behaviorConfiguration="">
            <endpoint name="DefaultEndPoint" address="http://localhost:54893/AttachmentService.svc"
                      behaviorConfiguration="EndpointBehaviors"
                      binding="wsHttpBinding" bindingName="AttachmentBinding"
                      contract="AttachmentsService.IAttachmentService"></endpoint>
          </service>
        </services>
    
        <behaviors>
          <serviceBehaviors>
            <behavior name="">
              <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="true"/>
              <dataContractSerializer maxItemsInObjectGraph="2147483647" />
            </behavior>
          </serviceBehaviors>
    
          <endpointBehaviors>
            <behavior name="EndpointBehaviors">
              <dataContractSerializer maxItemsInObjectGraph="2147483647" />
            </behavior>
          </endpointBehaviors>
        </behaviors>
    
        <bindings>
          <basicHttpBinding>
            <binding name="AttachmentBinding" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" receiveTimeout="00:01:00" sendTimeout="00:01:00"
                     textEncoding="utf-8" openTimeout="00:01:00">
              <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
              <security mode="None" />
            </binding>
          </basicHttpBinding>
        </bindings>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
      </system.serviceModel>
    

    有什么我遗漏的吗?

    我在使用IIS服务器上载大文件时也遇到了同样的问题

    我发现有两个地方需要修改
    web.config

    <system.web>
        <httpRuntime maxRequestLength="50000"/>
    </system.web>
    
    
    

    
    
    希望这有帮助

    详情如下:

    我终于解决了这个问题,以下是我的配置文件:

    WCF服务web.config文件:

        <?xml version="1.0"?>
    <configuration>
      <system.web>
        <compilation debug="true" targetFramework="4.0" />
        <httpRuntime maxRequestLength="2147483647" />
      </system.web>
    
      <system.serviceModel>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
        <services>
          <!-- The name of the service -->
          <service name="WcfService1.Service1">
            <!--you can leave the address blank or specify your end point URI-->
            <endpoint binding="webHttpBinding" bindingConfiguration="higherMessageSize" contract="WcfService1.IService1" behaviorConfiguration="Web" />
          </service>
        </services>
        <bindings>
          <webHttpBinding>
            <!-- configure the maxReceivedMessageSize value to suit the max size of the request (in bytes) you want the service to receive-->
            <binding name="higherMessageSize" transferMode="Streamed" maxReceivedMessageSize="2147483647" />
          </webHttpBinding>
        </bindings>
    
        <behaviors>
          <serviceBehaviors>
            <behavior>
              <serviceMetadata httpGetEnabled="true"/>
              <serviceDebug includeExceptionDetailInFaults="false"/>
            </behavior>
          </serviceBehaviors>
          <endpointBehaviors>
            <behavior name="Web">
              <webHttp/>
            </behavior>
          </endpointBehaviors>
        </behaviors>
        <!--<serviceHostingEnvironment multipleSiteBindingsEnabled="false" />-->
      </system.serviceModel>
    
      <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
      </system.webServer>
    </configuration>
    
    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <system.web>
        <compilation debug="true" targetFramework="4.0" />
        <httpRuntime maxRequestLength="2147483647" />
      </system.web>
    
      <system.serviceModel>
        <bindings>
          <webHttpBinding>
            <binding name="BasicHttpBinding_IService1" maxReceivedMessageSize="2147483647" />
          </webHttpBinding>
        </bindings>
        <client>
          <endpoint address="http://localhost:59540/Service1.svc" behaviorConfiguration="webhttp"
            binding="webHttpBinding" bindingConfiguration="BasicHttpBinding_IService1"
            contract="ServiceReference1.IService1" name="BasicHttpBinding_IService1" />
        </client>
        <behaviors>
          <endpointBehaviors>
            <behavior name="webhttp">
              <webHttp/>
            </behavior>
          </endpointBehaviors>
        </behaviors>
      </system.serviceModel>
    </configuration>
    
    
    
    客户端app.config/web.config文件:

        <?xml version="1.0"?>
    <configuration>
      <system.web>
        <compilation debug="true" targetFramework="4.0" />
        <httpRuntime maxRequestLength="2147483647" />
      </system.web>
    
      <system.serviceModel>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
        <services>
          <!-- The name of the service -->
          <service name="WcfService1.Service1">
            <!--you can leave the address blank or specify your end point URI-->
            <endpoint binding="webHttpBinding" bindingConfiguration="higherMessageSize" contract="WcfService1.IService1" behaviorConfiguration="Web" />
          </service>
        </services>
        <bindings>
          <webHttpBinding>
            <!-- configure the maxReceivedMessageSize value to suit the max size of the request (in bytes) you want the service to receive-->
            <binding name="higherMessageSize" transferMode="Streamed" maxReceivedMessageSize="2147483647" />
          </webHttpBinding>
        </bindings>
    
        <behaviors>
          <serviceBehaviors>
            <behavior>
              <serviceMetadata httpGetEnabled="true"/>
              <serviceDebug includeExceptionDetailInFaults="false"/>
            </behavior>
          </serviceBehaviors>
          <endpointBehaviors>
            <behavior name="Web">
              <webHttp/>
            </behavior>
          </endpointBehaviors>
        </behaviors>
        <!--<serviceHostingEnvironment multipleSiteBindingsEnabled="false" />-->
      </system.serviceModel>
    
      <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
      </system.webServer>
    </configuration>
    
    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <system.web>
        <compilation debug="true" targetFramework="4.0" />
        <httpRuntime maxRequestLength="2147483647" />
      </system.web>
    
      <system.serviceModel>
        <bindings>
          <webHttpBinding>
            <binding name="BasicHttpBinding_IService1" maxReceivedMessageSize="2147483647" />
          </webHttpBinding>
        </bindings>
        <client>
          <endpoint address="http://localhost:59540/Service1.svc" behaviorConfiguration="webhttp"
            binding="webHttpBinding" bindingConfiguration="BasicHttpBinding_IService1"
            contract="ServiceReference1.IService1" name="BasicHttpBinding_IService1" />
        </client>
        <behaviors>
          <endpointBehaviors>
            <behavior name="webhttp">
              <webHttp/>
            </behavior>
          </endpointBehaviors>
        </behaviors>
      </system.serviceModel>
    </configuration>
    
    
    

    我希望这能节省我花在解决这个问题上的时间:-)

    也许这能帮助你。我想您需要在绑定中使用
    transfermode
    。遵循
        <?xml version="1.0"?>
    <configuration>
      <system.web>
        <compilation debug="true" targetFramework="4.0" />
        <httpRuntime maxRequestLength="2147483647" />
      </system.web>
    
      <system.serviceModel>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
        <services>
          <!-- The name of the service -->
          <service name="WcfService1.Service1">
            <!--you can leave the address blank or specify your end point URI-->
            <endpoint binding="webHttpBinding" bindingConfiguration="higherMessageSize" contract="WcfService1.IService1" behaviorConfiguration="Web" />
          </service>
        </services>
        <bindings>
          <webHttpBinding>
            <!-- configure the maxReceivedMessageSize value to suit the max size of the request (in bytes) you want the service to receive-->
            <binding name="higherMessageSize" transferMode="Streamed" maxReceivedMessageSize="2147483647" />
          </webHttpBinding>
        </bindings>
    
        <behaviors>
          <serviceBehaviors>
            <behavior>
              <serviceMetadata httpGetEnabled="true"/>
              <serviceDebug includeExceptionDetailInFaults="false"/>
            </behavior>
          </serviceBehaviors>
          <endpointBehaviors>
            <behavior name="Web">
              <webHttp/>
            </behavior>
          </endpointBehaviors>
        </behaviors>
        <!--<serviceHostingEnvironment multipleSiteBindingsEnabled="false" />-->
      </system.serviceModel>
    
      <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
      </system.webServer>
    </configuration>
    
    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <system.web>
        <compilation debug="true" targetFramework="4.0" />
        <httpRuntime maxRequestLength="2147483647" />
      </system.web>
    
      <system.serviceModel>
        <bindings>
          <webHttpBinding>
            <binding name="BasicHttpBinding_IService1" maxReceivedMessageSize="2147483647" />
          </webHttpBinding>
        </bindings>
        <client>
          <endpoint address="http://localhost:59540/Service1.svc" behaviorConfiguration="webhttp"
            binding="webHttpBinding" bindingConfiguration="BasicHttpBinding_IService1"
            contract="ServiceReference1.IService1" name="BasicHttpBinding_IService1" />
        </client>
        <behaviors>
          <endpointBehaviors>
            <behavior name="webhttp">
              <webHttp/>
            </behavior>
          </endpointBehaviors>
        </behaviors>
      </system.serviceModel>
    </configuration>