WCF下上传大文件错误~ 求解


我用流的方式上传文件,文件大小在几M的时候上传没问题,但是如果文件大小超过一定量就报404错误,我的web.config如下:

<system.serviceModel>
    <!--<bindings>
      <customBinding>
        <binding name="customBinding">
          <binaryMessageEncoding>
            <readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647" maxDepth="64"/>
          </binaryMessageEncoding>
          <httpTransport maxReceivedMessageSize="2147483647">
          </httpTransport>
        </binding>
      </customBinding>
      <basicHttpBinding>
        <binding name="basicBinding" maxReceivedMessageSize="2147483647">
          <readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647" maxDepth="64"/>
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="" name="DataService.Service1">
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicBinding" contract="DataService.IDataService" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          --><!-- 为避免泄漏元数据信息,请在部署前将以下值设置为 false --><!--
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          --><!-- 要接收故障异常详细信息以进行调试,请将以下值设置为 true。在部署前设置为 false 以避免泄漏异常信息 --><!--
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https"/>
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>-->
    <bindings>
      <basicHttpBinding>
        <!--<binding name="basicBinding" maxReceivedMessageSize="2147483647"  messageEncoding="Text" transferMode="Streamed" sendTimeout="00:30:00" />-->
        <binding name="BasicHttpBinding_IDataService" closeTimeout="00:03:00"
                 openTimeout="00:03:00" receiveTimeout="00:30:00" sendTimeout="00:03:00"  maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="9223372036854775807"
                 messageEncoding="Text" transferMode="Streamed">
          <readerQuotas maxDepth="32" maxStringContentLength="90000000" maxArrayLength="90000000"
           maxBytesPerRead="90000000" maxNameTableCharCount="90000000" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="DataService.IDataServiceBehavior" name="DataService.Service1">
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IDataService" contract="DataService.IDataService" >
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="DataService.IDataServiceBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug  includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

客户端是winform,app.config如下:
 <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IDataService" closeTimeout="00:03:00"
                  openTimeout="00:03:00" receiveTimeout="00:30:00" sendTimeout="00:03:00"  maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="9223372036854775807"
                  messageEncoding="Text" transferMode="Streamed">
             <readerQuotas maxDepth="32" maxStringContentLength="90000000" maxArrayLength="90000000"
              maxBytesPerRead="90000000" maxNameTableCharCount="90000000" />
                  </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:27324/DataService.svc" binding="basicHttpBinding"
                bindingConfiguration="BasicHttpBinding_IDataService" contract="DataService.IDataService"
                name="BasicHttpBinding_IDataService" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        </client>
    </system.serviceModel>

按照网上的文章该设置的都设置了~ 可是只要文件一大,直接没调用wcf里的uploadfile,直接报404错误

7 个解决方案

#1


大文件本来就不适合
用ftp把

#2


因为多数文件大小都在几M到几百M 所以不想再搞个FTP ,有没有高手指点一下上面的配置文件有没有错误的地方。因为我在上传大文件的时候,wcf根本就没有调用上传文件的方法。

#3


几M还是可以  几百 靠http协议有点....
除了要配置wcf外,如果你的宿主是asp.net,那么还需要配置asp.net的上传文件最大限制

#4


直接这么上传肯定内存爆。

用第三方的上传控件,人家 是分块分块的上传,这样还能显示进度呢。

#5


因为都是在本地内网~ 所以无所谓的~ 关键是今天要把功能修改搞定才行

#6


原因找到了~ 因为我的程序是设计为动态绑定WCF地址的,所以换用固定的配置上传没有问题。我的绑定代码如下:

 BasicHttpBinding ws = new BasicHttpBinding();
                ws.MaxBufferSize = 2147483647;
                ws.MaxBufferPoolSize = 2147483647;
                ws.MaxReceivedMessageSize = 2147483647;
                
                ws.ReaderQuotas.MaxStringContentLength = 2147483647;
                ws.CloseTimeout = new TimeSpan(0, 10, 0);
                ws.OpenTimeout = new TimeSpan(0, 10, 0);
                ws.ReceiveTimeout = new TimeSpan(0, 10, 0);
                ws.SendTimeout = new TimeSpan(0, 20, 0);

                bindinginstance = ws;


可是用程序动态绑定的就不行,求指点

#7


自己搞定了~谢谢各位~ 

注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
© 2014-2019 ITdaan.com 粤ICP备14056181号