Emil Sylvest Jensen
Emil Sylvest Jensen

Reputation: 53

WCF Streaming not able to transfer large files

I am making a WCF Service for transfering files. I have only basic WCF understanding and followed the MSDN tutorial: WCF Tutorial I started using byte arrays for transfering the files but as soon as the files got a little big (100kb was enough) it would fail with bad request. I followed another guide and changed to streaming with messages, and it works with small files as well but fails with bigger ones like the old version. I suspect the fault lies in my config file as the one generated by svcutil.exe doesn't say anything about streaming. This is my clients app.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
    <bindings>
        <wsHttpBinding>
            <binding name="WSHttpBinding_IDocPublisher" closeTimeout="00:01:00"
                openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
                bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                maxBufferPoolSize="200000000" maxReceivedMessageSize="200000000"
                messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                allowCookies="false">
                <readerQuotas maxDepth="200000000" maxStringContentLength="200000000" maxArrayLength="200000000"
                    maxBytesPerRead="200000000" maxNameTableCharCount="200000000" />
                <reliableSession ordered="true" inactivityTimeout="00:10:00"
                    enabled="false" />
                <security mode="Message">
                    <transport clientCredentialType="Windows" proxyCredentialType="None"
                        realm="" />
                    <message clientCredentialType="Windows" negotiateServiceCredential="true"
                        algorithmSuite="Default" />
                </security>
            </binding>
        </wsHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://localhost:8000/ServiceModelSamples/docPublisherWebService/docPublisher"
            binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IDocPublisher"
            contract="IDocPublisher" name="WSHttpBinding_IDocPublisher">
            <identity>
                <userPrincipalName value="Emil-PC\Emil" />
            </identity>
        </endpoint>
    </client>
</system.serviceModel>
</configuration>

And this is the servers app.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<behaviors>
  <serviceBehaviors>
    <behavior name="serviceBehavior">
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="true"
                          httpHelpPageEnabled="true" />
      <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
<services>
  <service behaviorConfiguration="serviceBehavior"
              name="DocPublisher">
    <endpoint address="http://localhost:8000/ServiceModelSamples/docPublisherWebService"
              name="basicHttpStream"
              binding="basicHttpBinding"
              bindingConfiguration="httpLargeMessageStream"
              contract="IDocPublisher" />
    <endpoint address="mex"
                  binding="mexHttpBinding"
                  contract="IMetadataExchange"/>
  </service>
</services>
<bindings>
  <basicHttpBinding>
    <binding name="httpLargeMessageStream"
                maxReceivedMessageSize="200000000"
                maxBufferSize="200000000"
                transferMode="Streamed"
                messageEncoding="Mtom" />
  </basicHttpBinding>
</bindings>
</system.serviceModel>
</configuration>

Upvotes: 2

Views: 434

Answers (2)

Emil Sylvest Jensen
Emil Sylvest Jensen

Reputation: 53

Turns out the config files weren't the real problem, the problem was that the servers app.config was never used as the msdn tutorial doesn't use app.config but creates the endpoints in the main method.

Upvotes: 1

paramosh
paramosh

Reputation: 2258

Try to increase send timeout and reader quotas on client side, set buffer size on server side.

Upvotes: 1

Related Questions