开发者

Transferring large files using WCF and ASP.NET web forms

I'm trying to upload large files (upto 200MB) via ASP.NET web forms and store them in the database. I am able to upload large files using FileUpload control and I have setup a field in SQL Server as VarBinary(MAX) FileStream to store the files externally. I want to transfer the uploaded file using WCF service to the database and this is where I'm stuck. The only problem I have is when I try to stream the file from the code behind to the WCF service.

Settings: Client web.config in ASP.NET application

<system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IFileTransfer" maxReceivedMessageSize="2147483647"
                 maxBufferSize="2147483647" maxBufferPoolSize="2147483647"
                 transferMode="Streamed" messageEncoding="Mtom"
                 sendTimeout="24.20:31:23.6470000" receiveTimeout="24.20:31:23.6470000">
          <readerQuotas maxArrayLengt开发者_开发百科h="2147483647" maxBytesPerRead="2147483647"
                        maxDepth="2147483647" maxStringContentLength="2147483647"/>
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None"
              realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:25333/FileTransfer.svc" binding="basicHttpBinding"
        bindingConfiguration="BasicHttpBinding_IFileTransfer" contract="FileTransfer.IFileTransfer"
        name="BasicHttpBinding_IFileTransfer" />
    </client>
  </system.serviceModel>

Server web.config in WCF application

<system.serviceModel>
    <services>
      <service name="Ward.POC1.FileStream">
        <endpoint address="ep1" binding="basicHttpBinding" contract="WcfServiceHost.IFileTransfer">
          <identity>
            <dns value="localhost" />
            <certificateReference storeName="My" storeLocation="LocalMachine"
              x509FindType="FindBySubjectDistinguishedName" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <bindings>
      <basicHttpBinding>
        <binding maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" 
                 maxBufferPoolSize="2147483647"
                 transferMode="Streamed" messageEncoding="Mtom" 
                 sendTimeout="24.20:31:23.6470000" receiveTimeout="24.20:31:23.6470000">
          <readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647" 
                        maxDepth="2147483647" maxStringContentLength="2147483647"/>
        </binding>
      </basicHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="False"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

I've used transferMode="Streamed" with the following contract definition:

[ServiceContract]
public interface IFileTransfer
{
    [OperationContract]
    Stream GetFile(Guid fileId);

    [OperationContract]
    void AddFile(Stream fileStream);
}

Depending upon the change in the configuration settings I either get the following exception:

The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '24.20:31:23.6100000'.

or

WCF The remote server returned an error: (400) Bad Request.

Can anyone provide me with guidance on transferring uploaded large files between ASP.NET and another hosted application using WCF? I'm trying with Streaming. If anyone has elegant solution using binary array/chunking then its welcome too.


https://skydrive.live.com/?cid=41ce408c159c69ea&sc=documents&id=41CE408C159C69EA%21321

I had similar issue. I Hosted WCF as WAS service and it worked fine. It has to do somewith with configuraton and I am not sure what it is?

Also, other interesting thing I noted is that if I keep the code in the code behind generated by WCF itself, it works. ( Mtom / stream configuration). But if I seperate the code behind(interface and implementation) to different directory, it fails. I ended up using the same code with WAS instead of IIS and everything works fine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜