1

Good day.

I have the following question:

How to put the following object

[DataContract]
public class TimeItem
{
    [DataMember]
    public DateTime LocalTime { get; set; }
    [DataMember]
    public double XPos { get; set; }
    [DataMember]
    public double YPos { get; set; }
    [DataMember]
    public byte[] ScreenImage { get; set; } //Could be very huge
}

to the WCF service? (I write the WCF service as well, so I can customize it if I need). It works fine, but, in case of large bytes array (ScreenImage) I get an error 400 (Bad service request).

user306080
  • 1,409
  • 3
  • 16
  • 37
  • Could you please update your question with response body? Use fiddler or similar to get it. Presume we'll see an exception message and stacktrace there. – Sergei B. Oct 10 '11 at 10:45

4 Answers4

2

Take a look at this article on MSDN regarding the transfer of large data to/fro a WCF service. It will require you to change your data contract to a Message Contract, using the MessageContractAttribute instead of DataContract, MessageHeaderAttribute instead of DataMember on all but the large data field, and then the MessageBodyMemberAttribute on the byte data - which should be changed to a Stream.

Please note that the streams received this way tend to return false on the CanSeek property so be careful how you read the data from the stream.

You may also need to adjust your message size allowances on both client and server side configurations, using something similar to that described here

Hope that helps

Community
  • 1
  • 1
Smudge202
  • 4,689
  • 2
  • 26
  • 44
2

Maybe u need to increase the size of ur wcf message size (in web config file).

check this link, May this help

Community
  • 1
  • 1
Boomer
  • 1,468
  • 1
  • 15
  • 19
  • @user306080 - and did u set the MaxItemInObjectGraph? (Link: http://blog.hill-it.be/2007/08/22/maxitemsinobjectgraph-and-keeping-references-when-serializing-in-wcf-2/) – Boomer Oct 10 '11 at 08:50
2

You can use maxReceivedMessageSize attribute of a binding definition. It will allow you to send larger requests.

...
  <wsHttpBinding>
    <binding name="httpBinding" 
    maxBufferPoolSize="965536"
    maxReceivedMessageSize="965536">
      <readerQuotas maxStringContentLength="965536" />
    </binding>
  </wsHttpBinding>
...
Sergei B.
  • 3,227
  • 19
  • 18
1

There are things you can do to allow larger arrays (changing the serialization quotas; using MTOM; etc), but ultimately there is a limit to what you can send as a single message. It sounds like you are going to be bumping against the limit no matter what you do, so I would suggest looking at redesigning the API to take fragments of the data in separate messages, and re-combine at the server.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900