我们遇到以下错误:
反序列化Project.ModelType类型的对象时出错。读取XML数据时已超出最大字符串内容长度配额(8192)。可以通过更改在创建XML读取器时使用的MaxStringContentLength对象上的XmlDictionaryReaderQuotas属性来增加此配额。
有大量的文章,论坛帖子等,展示了如何增加MaxStringContentLength的服务规模。我遇到的问题是,所有这些示例都使用绑定,而我们不使用绑定。我们没有在服务项目的web.config中设置绑定或端点配置。我们使用的是.cs文件,而不是.svc文件。我们已经实现了RESTful WCF服务。
在客户端,我们使用WebChannelFactory调用我们的服务。
ASP.NET 4.0
有什么想法吗?
发布于 2011-08-10 16:53:30
您确实有一个绑定,只是WebChannelFactory是自动为您设置的。事实证明,这个工厂总是用WebHttpBinding创建一个端点,因此您可以在创建第一个通道之前更改绑定属性--参见下面的示例。
public class StackOverflow_7013700
{
[ServiceContract]
public interface ITest
{
[OperationContract]
string GetString(int size);
}
public class Service : ITest
{
public string GetString(int size)
{
return new string('r', size);
}
}
public static void Test()
{
string baseAddress = "http://" + Environment.MachineName + ":8000/Service";
WebServiceHost host = new WebServiceHost(typeof(Service), new Uri(baseAddress));
host.Open();
Console.WriteLine("Host opened");
WebChannelFactory<ITest> factory = new WebChannelFactory<ITest>(new Uri(baseAddress));
(factory.Endpoint.Binding as WebHttpBinding).ReaderQuotas.MaxStringContentLength = 100000;
ITest proxy = factory.CreateChannel();
Console.WriteLine(proxy.GetString(100).Length);
try
{
Console.WriteLine(proxy.GetString(60000).Length);
}
catch (Exception e)
{
Console.WriteLine("{0}: {1}", e.GetType().FullName, e.Message);
}
((IClientChannel)proxy).Close();
factory.Close();
Console.Write("Press ENTER to close the host");
Console.ReadLine();
host.Close();
}
}https://stackoverflow.com/questions/7013700
复制相似问题