zoukankan      html  css  js  c++  java
  • WCF服务端返回:(413) Request Entity Too Large

    出现这个原因我们应该都能猜测到,文件传出过大,超出了WCF默认范围,那么我们需要进行修改。

    服务端和客户端都需要修改。

    第一、客户端:

    <system.serviceModel>
            <bindings>
                <basicHttpBinding>
                    <binding name="BasicHttpBinding_ITaskService"  />
                </basicHttpBinding>
            </bindings>
            <client>
                <endpoint address="http://localhost:9001/wcf/TaskService.svc"
                    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ITaskService"
                    contract="BZAService.ITaskService" name="BasicHttpBinding_ITaskService" />
            </client>
        </system.serviceModel>
    

      

    上面是wcf客户端默认生成的,如需要修改传输文件大小,需要一下改动

         
    <binding name="BasicHttpBinding_ITaskService" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
    

      

     
    第二、服务端:
     
    <system.serviceModel>
           <services>    
          <service name="BZACenterService.AssetService.TaskService">
            <endpoint address="" binding="basicHttpBinding" contract="BZACenterService.AssetService.ITaskService">
              <identity>
                <dns value="localhost" />
              </identity>
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
            <host>
              <baseAddresses>
                <add baseAddress="http://localhost:8733/Design_Time_Addresses/BZACenterService.AssetService/TaskService/" />
              </baseAddresses>
            </host>
          </service>      
        </services>
        <behaviors>
          <serviceBehaviors>
            <behavior>       
              <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>       
              <serviceDebug includeExceptionDetailInFaults="False" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
      </system.serviceModel>
    

      上面是服务端默认配置,我们发现并没有bindings,如何设置那,方法是手动在<services>上增加如下

    <bindings>
         <basicHttpBinding>
            <binding name="LargeDataTransferServicesBinding" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647"
                 transferMode="Streamed" sendTimeout="00:10:00" />
    </binding>
    

      然后记得在在service 力的endpoint  增加属性 bindingConfiguration="LargeDataTransferServicesBinding"

    最终如下:

    <system.serviceModel>
     <bindings>
          <basicHttpBinding>
            <binding name="LargeDataTransferServicesBinding" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647"
                      transferMode="Streamed" sendTimeout="00:10:00"
                     />
          </basicHttpBinding>
        </bindings>
           <services>    
          <service name="BZACenterService.AssetService.TaskService">
            <endpoint address="" binding="basicHttpBinding" contract="BZACenterService.AssetService.ITaskService">
              <identity>
                <dns value="localhost" />
              </identity>
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
            <host>
              <baseAddresses>
                <add baseAddress="http://localhost:8733/Design_Time_Addresses/BZACenterService.AssetService/TaskService/" />
              </baseAddresses>
            </host>
          </service>      
        </services>
        <behaviors>
          <serviceBehaviors>
            <behavior>       
              <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>       
              <serviceDebug includeExceptionDetailInFaults="False" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
      </system.serviceModel>
    

     第三、测试运行

          最后编译运行,正常调用wcf了。

  • 相关阅读:
    tty 与 多任务的解释备忘
    Oracle 安装时候的fs.filemax参数
    100多个Web2.0在线生成器
    精心整理的微软原版光盘
    WEB3.0开启商务魔法时代
    VBO与Displaylists的进一步讨论 (转)
    基于UML和ASP.NET实现三层B/S结构系统开发(转)
    BYTE* To Float*
    COM高手总结的八个经验和教训(转)
    OpenGL: 3D坐标到屏幕坐标的转换逻辑(gluProject的实现)(转)
  • 原文地址:https://www.cnblogs.com/clc2008/p/7250142.html
Copyright © 2011-2022 走看看