-1
我有一个简单的自己托管的 WCF控制台窗口应用程序,我可以很好地连接到我的客户端。 虽然通过发送大型XML字符串到服务器,但我有一个问题。我得到以下错误:在自行托管的c#WCF控制台应用程序中使用web.config
“System.Xml.XmlException:最大字符串内容长度配额(8192),而读取XML数据已经超过了这个限额可通过更改XmlDictionaryReaderQuotas的MaxStringContentLength财产增加。 ..”
我可以通过改变它的app.config文件(由svcutil.exe的生成)设置MaxStringContentLength在客户。
但在服务器端我无处可以改变这一点。我已经阅读了关于web.config文件,我不确定WCF控制台应用程序是否可以有一个,如果可以,我如何读取它并使用它?我的自我托管代码如下:
static void RunWCFService()
{
// Step 1 of the address configuration procedure: Create a URI to serve as the base address.
Uri baseAddress = new Uri("http://localhost:8000/MyService/WcfService");
// Step 2 of the hosting procedure: Create ServiceHost
ServiceHost selfHost = new ServiceHost(typeof(MyServiceWcf), baseAddress);
try
{
// Step 3 of the hosting procedure: Add a service endpoint.
selfHost.AddServiceEndpoint(typeof(IMyService), new WSHttpBinding(), "MyService");
// Step 4 of the hosting procedure: Enable metadata exchange.
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
selfHost.Description.Behaviors.Add(smb);
// Step 5 of the hosting procedure: Start (and then stop) the service.
selfHost.Open();
Console.WriteLine("Press <ENTER> to terminate service.");
Console.ReadLine();
// Close the ServiceHostBase to shutdown the service.
selfHost.Close();
}
catch (CommunicationException ce)
{
Console.WriteLine("An exception occurred: {0}", ce.Message);
selfHost.Abort();
}
}
而我的问题是如何在上面的代码中使用app.config信息,还是自动使用? – 2010-10-04 16:08:56
@Andrew White:如果你把配置放在正确的位置,WCF将从那里读取 - 完全自动化。 – 2010-10-04 16:17:22