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