Maximum length exceeded - Error

Last post 11-08-2006 10:38 AM by skb. 2 replies.

Sort Posts:

  • Maximum length exceeded - Error

    11-07-2006, 10:20 PM
    • Member
      35 point Member
    • skb
    • Member since 06-19-2006, 4:07 PM
    • Texas
    • Posts 18

    I am currently receiving an error "Maximum length exceeded" when calling a web service method that returns a list of objects.  I have not found any configuration entry to set the response max length.  If I call the web service (http://localhost/test/locations.asmx) and invoke a test on the method, all works correctly.  If I call the web service via the javascript proxy, I receive the error.  Does anyone have any ideas? Am I missing something?  See code below:

     

    Page:
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Untitled Page</title>
        <script type="text/javascript" language="javascript">
        function getLocations(code) {
            debug.trace("calling web service for return locations");
            Locations.GetReturnLocations(code, locationSearchComplete, onError, code);
        }
       
        function locationSearchComplete(result, userContext, methodName) {
            debug.trace("return location complete");
            var results = $get("results");
            if (results) {
                results.innerText = result;
            }
        }
       
        function onError(error, userContext, methodName) {
            debug.trace(error.get_message());
        }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <asp:ScriptManager ID="ScriptManager1" runat="server">
                <Services>
                    <asp:ServiceReference path="~/Locations.asmx" />
                </Services>
            </asp:ScriptManager>   
            <div>
                <button id="go" type="button" onclick="javascript:getLocations('dfw');">Go</button>
                <br />
                <div id="results"></div>
                <br />
                <br />
                <div style="float:right;">
                    <textarea cols="50" rows="10" id="TraceConsole"></textarea>
                </div>
            </div>
        </form>
    </body>
    </html>


    Web Service:
    using System;
    using System.Web;
    using System.Collections;
    using System.Web.Services;
    using System.Web.Services.Protocols;
    using System.Text;
    using System.Collections;
    using System.Collections.Generic;

    /// <summary>
    /// Summary description for Locations
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [Microsoft.Web.Script.Services.ScriptService]
    public class Locations : System.Web.Services.WebService {

        public Locations () {

            //Uncomment the following line if using designed components
            //InitializeComponent();
        }

        [WebMethod]
        public List<string> GetReturnLocations(string code) {
            List<string> loc = new List<string>();
     
            StringBuilder sb = new StringBuilder();
            sb.Append("aaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbcccccccccccccccccccccccccccccccdddddddddddddddddddddddd");
            sb.Append("eeeeeeeeeeeeeeeeeeeffffffffffffffffgggggggggggggghhhhhhhhhhhhiiiiiiiiiiiijjjjjjjjjjjkkkkkkkkkkkkkkkkkkkkkk");
            sb.Append("lllllllllllllmmmmmmmmmmmmmmnnnnnnnnnnnnnnnnnooooooooooooooppppppppppppppppppqqqqqqqqqqqqqqqrrrrrrrrrrrrrrr");
            sb.Append("sssssssssssssssttttttttttttttttuuuuuuuuuuuuuuuuuvvvvvvvvvvvvvvvvvvvvwwwwwwwwwwwwwwwwwwwwxxxxxxxxxxxxxxxxxx");
            sb.Append("yyyyyyyyyyyyyyyyyyyyyyyyyyyyyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz");
            sb.Append("aaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbcccccccccccccccccccccccccccccccdddddddddddddddddddddddd");
            sb.Append("eeeeeeeeeeeeeeeeeeeffffffffffffffffgggggggggggggghhhhhhhhhhhhiiiiiiiiiiiijjjjjjjjjjjkkkkkkkkkkkkkkkkkkkkkk");
            sb.Append("lllllllllllllmmmmmmmmmmmmmmnnnnnnnnnnnnnnnnnooooooooooooooppppppppppppppppppqqqqqqqqqqqqqqqrrrrrrrrrrrrrrr");
            sb.Append("sssssssssssssssttttttttttttttttuuuuuuuuuuuuuuuuuvvvvvvvvvvvvvvvvvvvvwwwwwwwwwwwwwwwwwwwwxxxxxxxxxxxxxxxxxx");
            sb.Append("yyyyyyyyyyyyyyyyyyyyyyyyyyyyyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz");

            for (int i = 0; i < 100; i++)
            {
                loc.Add(sb.ToString());
            }

            return loc;
        }
    }

  • Re: Maximum length exceeded - Error

    11-08-2006, 2:21 AM
    Answer

    You have to set a maximum length appropriate for your Ajax app in the jsonSerialization tag in the web.config file.
    Look for this in your web.config file, uncomment and set the size you need:

    <!--

    Uncomment this line to customize maxJsonLength and add a custom converter -->
    <!--
    <jsonSerialization maxJsonLength="500">
    <converters>
    <add name="ConvertMe" type="Acme.SubAcme.ConvertMeTypeConverter"/>
    </converters>
    </jsonSerialization>
    --> 

    For example: <jsonSerialization maxJsonLength="500" />

    When you call the web service and invoke a test on the method, the size is not taken into account because who controls the length is the asynchronous communication layer not the web service itself.

    HTH,

    Maíra

    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: Maximum length exceeded - Error

    11-08-2006, 10:38 AM
    • Member
      35 point Member
    • skb
    • Member since 06-19-2006, 4:07 PM
    • Texas
    • Posts 18

    thanks for the help....it works. 

    steven

Page 1 of 1 (3 items)