使用Silverlight / WCF将大文件上载到数据库

时间:2011-11-01 15:18:44

标签: silverlight wcf

我有一个Silverlight应用程序,它使用位于Web项目中的WCF服务。我在服务中有一个方法,以二进制格式将文件上传到数据库...这对于大约6MB的文件都可以正常工作,但当我超过该限制时,我收到错误“远程服务器返回错误:未找到。”哪个不告诉我太多。

我已启用跟踪和日志记录,但我没有收到任何错误/消息。我认为有一个上传/传输大小的设置,但我不知道它会在哪里。我已经搞乱了web.config中的某些设置而没有成功。

我如何超越此限制?

编辑:也许我应该首先发布我的代码,我已经设置了所有建议的尺寸(并且总是有)......

<bindings>
  <basicHttpBinding>
    <binding name="TaskCalendarService.BasicHttpBinding" 
             maxBufferSize="2147483647" 
             maxReceivedMessageSize="2147483647" 
             maxBufferPoolSize="2147483647"
             transferMode="StreamedResponse">
      <readerQuotas maxDepth="2147483647" 
                    maxStringContentLength="2147483647"
                    maxArrayLength="2147483647" 
                    maxBytesPerRead="2147483647"
                    maxNameTableCharCount="2147483647" />
      <security mode="Transport">
        <transport clientCredentialType="None" />
      </security>
    </binding>
  </basicHttpBinding>
</bindings>

 <behaviors>
  <serviceBehaviors>
    <behavior name="TaskServiceBehavior">
      <serviceMetadata httpsGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
      <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
    </behavior>
  </serviceBehaviors>
</behaviors>

   <service name="TaskCalendarService" 
           behaviorConfiguration="TaskServiceBehavior">
    <endpoint address="" 
              binding="basicHttpBinding" 
              bindingConfiguration="TaskCalendarService.BasicHttpBinding" 
              contract="Pars.Web.TaskCalendarService" />
    <endpoint address="mex" 
              binding="mexHttpsBinding" 
              contract="IMetadataExchange" />
  </service>

正如您现在所看到的,我能想到的所有内容都已设置为足够大,以便能够处理超过6 MB,但我仍然会收到此错误。

编辑:错误

内部例外:

{System.Net.WebException:远程服务器返回错误:NotFound。 ---&GT; System.Net.WebException:远程服务器返回错误:NotFound。“ &安培; vbCrLf&amp; “在System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)”  &安培; vbCrLf&amp; “在System.Net.Browser.BrowserHttpWebRequest。&lt;&gt; c_ DisplayClass5.b _4(Object sendState)” &安培; vbCrLf&amp; “在System.Net.Browser.AsyncHelper。&lt;&gt; c_ DisplayClass4.b _1(Object sendState)” &安培; vbCrLf&amp; “---内部异常堆栈跟踪结束---”&amp; vbCrLf&amp; “
在System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod,Object state)“  &安培; vbCrLf&amp; “在System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)”  &安培; vbCrLf&amp; “at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result)}

在弹出错误窗口中,它还建议:

InnerException:检查异常的Response属性以确定请求失败的原因。 InnerException:检查异常的Status属性以确定请求失败的原因。

响应属性说:{System.NotImplementedException:此类未实现此属性。“&amp; vbCrLf&amp;”at System.Net.HttpWebResponse.get_Cookies()}

状态只是说:WebExceptionStatus.UnknownError(HttpStatusCode.NotFound)

堆栈追踪:

在System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod,Object state)    在System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)    at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result)

2 个答案:

答案 0 :(得分:2)

如果超时,您可以更新自定义绑定。我假设你在Web.config中有这样的东西:

<bindings>
  <customBinding>
    <binding name="CustomBinding_HelloWorldService">
      <binaryMessageEncoding />
      <httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
    </binding>
  </customBinding>
</bindings>

如果是这样,您可以更新绑定(我只是将其设置为10分钟):

<binding name="CustomBinding_HelloWorldService" sendTimeout="00:10:00">

如果你想更多地研究一下:custombinding

答案 1 :(得分:2)

您的问题的解决方案很简单,因为它是默认值<httpRuntime maxRequestLength/>,我认为是4mb,据我所知,它提供了WCF服务在一次调用中可以从客户端接收多少数据的信息。您只需在标签下的WCF服务中添加此标记,它应该如下所示

<system.web> <compilation debug="true" targetFramework="4.0" /> <httpRuntime maxRequestLength="2000000" /> </system.web>

此示例适用于2gb。

相关问题