-1

I am new to the C# world, just giving a heads up, because I know...I am probably going to some novice-like stuff, so apologies in advance. Here is my problem:

I have a CLR that calls a web service. The data returned from the web service gets too large for the CLR to handle and generates the following error:

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)

I have looked through some of the other posts with similar length quota errors, but most of the suggestions involve changing the app config. Because I am using a CLR, i do not have an app config and i am not sure if i can add an app config. I tried adding one using the instructions found on LINK but that is for a non-CLR project.

Help is kindly appreciated. Thanks in advance.

Here is a snippet of code to complement the error.

The exception comes up in the SQL Server side within the following function call:

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

The code below is from c#. The XML returned is too large and results in the exception at the top of this post:

    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
    To check - when you say 'a CLR' are you referring to a CLR stored procedure within SQL server? – Paddy Jan 13 '14 at 15:56
  • Did the instructions it gave not work? *This quota may be increased by changing the MaxStringContentLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader* – Cory Nelson Jan 13 '14 at 16:00
  • 1
    Not sure what you mean by "using a CLR." To me, that means *Common Language Runtime,* which I assume any writer of C# is using. – Jacob Jan 13 '14 at 16:05
  • See also http://stackoverflow.com/questions/969479/modify-endpoint-readerquotas-programatically – Peter Ritchie Jan 13 '14 at 16:12
  • Do you have an example of the code you're trying to execute that gets this exception? May be easier for someone to correlate to the above post if you're new to C# – Peter Ritchie Jan 13 '14 at 16:13
  • As others have guessed, it sounds like you're using a CLR Stored Procedure in SQL Server. If this is so, please post the code of the procedure. It's likely you'll need to change properties on the binding itself in code if you need to set these parameters. – Adam Robinson Jan 13 '14 at 16:18
  • @Paddy, yes...sorry for not being clear. it is a CLR user defined function within SQL server. I have looked at the other posts, but they mostly suggest changing the web/app config. But i dont have that in my project, and when i try to add it, Project->add new item, but it does not give me an option to add any kind of config file. – user2272229 Jan 13 '14 at 17:31
  • @PeterRitchie i have updated my initial post with the code. – user2272229 Jan 13 '14 at 21:48

1 Answers1

-1

There is a setting in your web.config or app.config called MaxStringContentLength that needs to be increased. If it isn't there then it's using the default settings and you need to add it. MSDN has good documentation on where in the config file to add it.

CodeMonkey1313
  • 15,717
  • 17
  • 76
  • 109