0

I have a WCF operation which is like this,

public bool SubmitDocument(byte[] document)

So the idea is that the caller will serialise a document, and call the operation above. It then gets put into our database.

I am trying to understand the internal workings of WCF, so when someone calls the operation above it seems logical that all of the byte[] data needs to be sent to the server before the actual operation is called.

Is there a way to 'log' when that data starts being uploaded to the server, and also catch an error if that fails part way through? I am having a problem with documents that are about 4mb failing part way through and my WCF service doesn't even register that someone is trying to call that operation.

I have increased the upload size limit like this,

<wsHttpBinding>
    <!-- The upload limit should be 5 Mb, rounding up to 6 Mb just to be sure -->
    <binding name="CarWebserviceBinding" maxReceivedMessageSize="6291456">
      <security mode="None">
      </security>
      <!-- The upload limit should be 5 Mb, rounding up to 6 Mb just to be sure -->
      <readerQuotas maxArrayLength="6291456" />
    </binding>
  </wsHttpBinding>

The problem overall is that a third party calls the WCF operation above (SubmitDocument) and the document never makes it to our end if it is over 4Mb.

peter
  • 13,009
  • 22
  • 82
  • 142

2 Answers2

3

You are exceeding the size of the default buffer size for WCF messages. You probably need to learn about TransferMode Streamed. There is a question about it here WCF HttpTransport: streamed vs buffered TransferMode

Community
  • 1
  • 1
Darrel Miller
  • 139,164
  • 32
  • 194
  • 243
2

I found the answer here,

http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/f6541134-2e08-4eb9-987b-2158fb99b403

So there are various WCF limits which I had already handled correctly like this,

<wsHttpBinding>
  <!-- The upload limit should be 5 Mb, rounding up to 6 Mb just to be sure -->
  <binding name="CarWebserviceBinding" maxReceivedMessageSize="6291456">
    <security mode="None">
    </security>
    <!-- The upload limit should be 5 Mb, rounding up to 6 Mb just to be sure -->
    <readerQuotas maxArrayLength="6291456" />
  </binding>
</wsHttpBinding>

BUT what I HADN'T done was this,

<system.web>
  <httpRuntime maxRequestLength="16384" /> <!-- 16MB -->
</system.web>

IIS has a default limit of around 4MB for any http requests that come in. The above settings overrides that limit.

Another thing to mention is that I added this to my web.config to turn on tracing,

<system.diagnostics>
  <sources>
    <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
      <listeners>
        <add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData="c:\logs\Traces.svclog" />
      </listeners>
    </source>
  </sources>
</system.diagnostics>

And in the error log turned up the error,

CommunicationException - Maximum request length exceeded
peter
  • 13,009
  • 22
  • 82
  • 142
  • And you're saying that when you added the `maxRequestLength`, you stopped getting 401 errors, and when you take it out again, you get 401 errors again? – John Saunders Mar 17 '11 at 22:20
  • Yes. Well the 401 thing is hard to comment on because those error logs came from a different company who are using our WCF service. I.e. I cannot see their code, and thus understand why it failed like that. – peter Mar 17 '11 at 22:37
  • What I can say for sure though is that when a person uploaded a document of size 4086kb to a website (which in term calls our WCF service) it never appears at our end without the setting, and with the setting it appears at our end no worries. – peter Mar 17 '11 at 22:38
  • I believe you when you say the setting makes it work; but your question says that the problem was a "401", and this setting wouldn't help with that at all. – John Saunders Mar 17 '11 at 22:47
  • Mate, I have removed the 401 part of the question. It is not really relevant. A separate company told me about the 401 errors, so they could have been something else. It is difficult for me to get accurate information from a third party, I don't see their code, and only get to talk to them occasionally using skype chat. Trace logging at my end told me that the problem was definitely 'Maximum request length exceeded'. – peter Mar 18 '11 at 01:08