2011-08-10 9 views
3

を増やし:WCFサービスのMaxStringContentLengthサイズを大きくする方法を示すなどの記事、フォーラムの投稿、、のトンがありますWCF + REST、次のエラーに我々が実行されているMaxStringContentLength

There was an error deserializing the object of type Project.ModelType. The maximum string content length quota (8192) has been exceeded while reading XML data. This quota may be increased by changing the MaxStringContentLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader.

。私が経験している問題は、これらの例のすべてがBindingを使用していることです.Bindingは使用しません。サービスプロジェクトのweb.configにバインドやエンドポイントの設定はありません。 .svcファイルではなく.csファイルを使用しています。私たちはRESTfulなWCFサービスを実装しました。

クライアント側では、WebChannelFactoryを使用してサービスに電話しています。

ASP.NET 4.0

アイデアはありますか?

+1

あなたは**あなたのサーバー側の「web.config」とクライアント上のコードを使ってプロキシを作成できますか? –

+0

どこにエラーが表示されますか?クライアントまたはサーバーでは? – carlosfigueira

+0

オブジェクトを逆シリアル化しようとすると、サーバー側でエラーが発生します。 – mtm927

答えて

1

あなたはバインディングを持っています、それは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(); 
    } 
} 
関連する問題