-1

我有一个简单的自托管WCF 控制台 Windows 应用程序,我可以从我的客户端正常连接。尽管将大型 XML 字符串发送到服务器,但我遇到了问题。我收到以下错误:

“System.Xml.XmlException:读取 XML 数据时超出了最大字符串内容长度配额 (8192)。可以通过更改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();
    }
 }
4

1 回答 1

3

WCF 配置数据进入app.config正在执行托管的 exe 中。

于 2010-10-04T15:37:58.900 回答