我正在实现一个分布式处理系统,其中客户端发送的请求的参数是一个对象列表(序列化)和另一个double值。因此,服务器和服务器以对象列表作为响应。我实现了服务器和客户端部分。
客户端部分:
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();
并在服务器端
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);
对象正在被序列化但如果我尝试发送超过4个元素的序列化列表,则表示在读取XML数据时超出了最大字符串内容长度。我纯粹在仅代码基础上实现这个(没有单独的配置文件)。我犯错的任何想法?
答案 0 :(得分:2)
我没有看到您将代码中定义的绑定分配给服务的位置 - 如果您不这样做,那么您将获得BasicHttpBinding
的默认值。 MaxStringContentLength
的默认值为8192.尝试将此类内容添加到服务的代码中:
host.AddServiceEndpoint(typeof(MarchingCubesInterface), serviceBind, "http://172.20.54.168:6525/ServerObject");
这将使用您在发布的代码中定义的绑定为服务添加具有指定地址的端点。
答案 1 :(得分:0)
问题可能在于您的服务器应用程序可能设置了硬限制。
检查服务的web.config
文件,并将通讯员MaxStringContentLength
(默认为8192或8KB)调整为您认为合适的值。
这是一篇类似的帖子:
Sending object to WCF service. MaxStringContentLength (8192 bytes) exceeded when deserializing