CLR长度配额错误

时间:2014-01-13 15:53:46

标签: c# .net

我是C#世界的新手,只是抬起头来,因为我知道......我可能会去做一些类似新手的事情,所以请提前道歉。这是我的问题:

我有一个调用Web服务的CLR。从Web服务返回的数据太大,CLR无法处理并生成以下错误:

Msg 6522, Level 16, State 1, Line 1
A .NET Framework error occurred during execution of user-defined routine or     
aggregate "fnGetReportData": 
System.Web.Services.Protocols.SoapException:The formatter threw an exception   
while trying to deserialize the message: There was an error while trying to     
deserialize parameter http://tempuri.org/:xmlTags. 
The InnerException message was 'There was an error deserializing the object of type
System.Collections.Generic.List`1[[System.String, mscorlib, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089]]. 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. Line 1, position   
9474.'.  Please see InnerException for more details. 
System.Web.Services.Protocols.SoapException: 
at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage 
message, WebResponse response, Stream responseStream, Boolean asyncCall) at 
System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, 
object[] parameters) at myService.RequestReport(String reportName, String[] xmlTags, 
String encryptedUserName, String encryptedPassword)
at myReportClr.UserDefinedFunctions.fnGetReportData(SqlString reportName, 
SqlString project, SqlXml reportTags, SqlString userName, SqlString password)

我查看了一些其他类似长度配额错误的帖子,但大多数建议都涉及更改应用配置。因为我使用的是CLR,我没有应用程序配置,我不确定是否可以添加应用程序配置。我尝试使用LINK上的说明添加一个,但这是针对非CLR项目的。

非常感谢帮助。提前谢谢。

以下是补充错误的代码片段。

在以下函数调用中SQL Server端出现异常:

SELECT @reportData  = (dbo.fnGetReportData
            ('DataCompare'
            ,@projectName
            ,@harnessXmlTags
            ,@user
            ,@password)
        );

以下代码来自c#。返回的XML太大,导致此帖子顶部出现异常:

    public static SqlXml fnGetReportData(
         SqlString reportName
        , SqlString project
        , SqlXml reportTags
        , SqlString userName
        , SqlString password
    )
    {
        String xmlResponse = " ";
        SqlXml reportData = SqlXml.Null;

        List<String> xmlTags = new List<String>();
        xmlTags.Add(CreateTag("Project", project.ToString()));
        xmlTags.Add(CreateTag("Configuration", "any"));
        xmlTags.Add(reportTags.Value);




        using (myService client = new myService())
        {
            xmlResponse =
                client.RequestReport(reportName.ToString()
                    , xmlTags.ToArray()
                    , userName.ToString()
                    , password.ToString()
            );
        }

        if (xmlResponse != null || !xmlResponse.Equals(""))
        {
            reportData = convertStringtoSqlXml(removeSoapHeader(xmlResponse, reportName.ToString()));
        }
        else
        {
            reportData = convertStringtoSqlXml(
                String.Format("{0} xmlns:xsi=\"www.myReport.com/myData\" xmlns:ns=\"uri\"", reportName)
            );
        }

        return reportData;
    } 

1 个答案:

答案 0 :(得分:-1)

您的web.config或app.config中有一个名为MaxStringContentLength的设置需要增加。如果它没有,那么它使用默认设置,您需要添加它。 MSDN有关于添加配置文件的位置的详细文档。