0

I am implementing a distributed processing system where clients send requests with parameters being one list of objects(serialized) and another double value. to the server and server responds back with a list of objects as a result. I implemented the server and client parts.

Client part:

BasicHttpBinding myBinding = new BasicHttpBinding();
myBinding.ReaderQuotas.MaxStringContentLength = Int32.MaxValue;
myBinding.MaxBufferSize = Int32.MaxValue;
myBinding.MaxReceivedMessageSize = Int32.MaxValue;
myBinding.ReaderQuotas.MaxArrayLength = Int32.MaxValue;

var myEndPoint = new EndpointAddress("http://172.20.54.168:6525/ServerObject");
var myChannelFactory = new ChannelFactory<MarchingCubesInterface>(myBinding, myEndPoint);
MarchingCubesInterface mc = null;
mc = myChannelFactory.CreateChannel();

and on server side

BasicHttpBinding serviceBind = new BasicHttpBinding();
serviceBind.ReaderQuotas.MaxStringContentLength = Int32.MaxValue;
serviceBind.MaxBufferSize = Int32.MaxValue;
serviceBind.MaxReceivedMessageSize = Int32.MaxValue;
serviceBind.ReaderQuotas.MaxArrayLength = Int32.MaxValue;
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
host.Description.Behaviors.Add(smb);

The objects are getting serialized but if i try to send a serialized list of more than 4 elements, it says The maximum string content length exceeded while reading XML data. I am implementing this purely on code-only base(no configuration files separately). Any ideas where I am making a mistake?

Habib
  • 219,104
  • 29
  • 407
  • 436
informeto
  • 162
  • 2
  • 14

2 Answers2

2

I don't see where you're assigning the binding you defined in your code to the service - if you're not doing that, then you will get the default values for BasicHttpBinding. The default value for MaxStringContentLength is 8192. Try adding something like this to your code for your service:

host.AddServiceEndpoint(typeof(MarchingCubesInterface), serviceBind, "http://172.20.54.168:6525/ServerObject");

This will add an endpoint with the specified address for the service using the binding you defined in your posted code.

Tim
  • 28,212
  • 8
  • 63
  • 76
0

The issue may lie in the fact that a hard limit may be set on your server application.

Check your service's web.config file, and adjust the correspondent MaxStringContentLength (default 8192, or 8KB) to whichever value you see fit.

Here's a similar post:

Sending object to WCF service. MaxStringContentLength (8192 bytes) exceeded when deserializing

Community
  • 1
  • 1
OnoSendai
  • 3,960
  • 2
  • 22
  • 46
  • The problem is i dont know where does this web.config file live? I didn't create it by myself. I can't find either. – informeto Nov 26 '13 at 15:13
  • The Web.config file can be found in the root directory of your Web Application. – OnoSendai Nov 26 '13 at 15:14
  • OP stated they weren't using any configuration files in the question. – Tim Nov 26 '13 at 15:51
  • While the OP mentioned that he didn't implement any configuration files, a default value expressed on a pre-existing web.config file could still potentially affect the server application behavior. But I'm glad you were able to point out the issue! – OnoSendai Nov 26 '13 at 16:43