0

Server code

public class SIIUnzipDecodeService : ISIIUnzipDecodeService
{
    //Upload the large data file

    public void UploadFile(RemoteFileInfo request)
    {
        FileStream targetStream = null;
        Stream sourceStream = request.FileByteStream;

        string uploadFolder = @"C:\upload\";
        string filePath = @"C:\upload\1GB.zip";
        //Path.Combine(uploadFolder, request.FileName);

        using (targetStream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None))
        {
            //read from the input stream in 6K chunks
            //and save to output stream
            const int bufferLen = 65000;
            byte[] buffer = new byte[bufferLen];
            int count = 0;

            while ((count = sourceStream.Read(buffer, 0, bufferLen)) > 0)
            {
                targetStream.Write(buffer, 0, count);
            }

            targetStream.Close();
            sourceStream.Close();
        }

    }

Interface.

[ServiceContract]
public interface ISIIUnzipDecodeService
{
    [OperationContract]
    void UnzipAndDecode(MemoryStream fileContent);

    [OperationContract]
    RemoteFileInfo DownloadFile(DownloadRequest request);

    [OperationContract]
    void UploadFile(RemoteFileInfo request);
}

[MessageContract]
public class DownloadRequest
{
    [MessageBodyMember]
    public string FileName;
}

[MessageContract]
public class RemoteFileInfo : IDisposable
{
    [MessageHeader(MustUnderstand = true)]
    public string FileName;

    [MessageHeader(MustUnderstand = true)]
    public long Length;

    [MessageBodyMember(Order = 1)]
    public System.IO.Stream FileByteStream;

    public void Dispose()
    {
        if (FileByteStream != null)
        {
            FileByteStream.Close();
            FileByteStream = null;
        }
    }
}
Tim
  • 27,313
  • 8
  • 59
  • 71
user359562
  • 57
  • 6

2 Answers2

1

Can you try enable Tracing on your service. Also please post your service configuration. Make sure that you have set the below things in your service configuration:

<dataContractSerializer maxItemsInObjectGraph="2147483647"/>

<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
            maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />

<basicHttpBinding>
        <binding transferMode="Buffered"/>
</basicHttpBinding>
Rajesh
  • 7,381
  • 5
  • 19
  • 34
  • Here is the web.config binding information. I tried to do what was suggested still no luck for me. Getting "Failed to allocate a managed memory buffer of 536870912 bytes. The amount of available memory may be low" – user359562 Jan 30 '12 at 07:01
0
<basicHttpBinding>
      <binding closeTimeout="00:30:00"
          openTimeout="00:30:00" receiveTimeout="00:30:00" sendTimeout="00:30:00"
          allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
          maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
          messageEncoding="Text" transferMode="Buffered"
          useDefaultWebProxy="true">
        <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"             maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
        <security mode="None">
          <transport clientCredentialType="None" proxyCredentialType="None"
            realm="" />
          <message clientCredentialType="UserName" algorithmSuite="Default"  />
        </security>
      </binding>
  </basicHttpBinding>
user359562
  • 57
  • 6
  • Assuming you have added the datacontractserializer element to the servicebehavior element in web.config and from the error message looks like the message that is being sent back if very huge. Try compressing the message or initially send back small message and see if that is successful – Rajesh Jan 30 '12 at 09:42
  • Also refer to this question on SO... http://stackoverflow.com/questions/3016446/transferring-large-payloads-of-data-serialized-objects-using-wshttp-in-wcf-wit – Rajesh Jan 30 '12 at 09:43