Search code examples
javascriptvb.netwebmethod

can javascript accept a string with length 27601?


I have a webmethod which will return an object with strings(i.e)str is object and str(0) would be string. str(0)'s length would be 27601. likewise all other array members having the same length.(i.e) str(1)'s length is 27601 also str(2),str(3)......

my webmethod return the exact object. but on the client side javascript doesn't accept the value it immediately fire the error method.

sample code is,

PageMethods.paging("","",pospara,"position_select","stored Procedure",function sucMulti(result){
alert(result);
});

web method is

<WebMethod()> _
<ScriptMethod()> _
Public Shared Function paging(ByVal query As String, ByVal tbl As String, ByVal para() As Object, ByVal spname As String, ByVal cmdtype As String) As Object()
     Dim dsrt As New DataSet, dbacc As New dataaccess
    If cmdtype = "stored Procedure" Then
        dsrt = dbacc.retds1(spname, conn, para)
    Else
        dsrt = dbacc.retds(query, tbl, conn)
    End If
    'here dsrt will have 19 rows. so i split them by 8.
    Dim no As Integer
    Dim rows As Integer = 8
    Dim r As Integer
    no = Floor(dsrt.Tables(0).Rows.Count / rows)
    If dsrt.Tables(0).Rows.Count < rows Then
        r = 0
    Else
        r = dsrt.Tables(0).Rows.Count Mod rows
    End If

    Dim start As Integer = 0
    Dim last As Integer = 7
    Dim str(0) As Object
    Dim dv As New DataView
    dv = dsrt.Tables(0).DefaultView
    If r <> 0 Then
        no += 1
    End If
    If no >= 1 Then
        ReDim str(no - 1)
        For i As Integer = 1 To no

            Dim ds As New DataSet
            Dim dt As New DataTable
            dt = dsrt.Tables(0).Clone
            dt.Rows.Clear()
            For j As Integer = start To last
                dt.ImportRow(dsrt.Tables(0).Rows(j))
            Next

            start = (rows * i) 
            If r <> 0 And i = no - 1 Then
                last = last + r
            Else
                last = start + 7
            End If
            ds.Tables.Add(dt)
            str(i - 1) = ds.GetXml

        Next
    Else
        str(0) = dsrt.GetXml
    End If
    Dim len As Integer = str(0).ToString.Length
    Return str
End Function

everything goes fine . str will contain 4 rows, each row would have a string with 27601 length. but javascript doesn't alert the result. why?


Solution

  • I found a solution that to increase the jason max length by the following.

    <system.web.extensions>
    <scripting>
      <webServices>
        <jsonSerialization maxJsonLength="5000"/>
      </webServices>
    </scripting>
    

    I put the above code inside the tag of web Config file.It works but it gives tooltip error message on the first tag. any suggestions to correct it?

    the error message is,

    "the element 'configuration' in namespace 'http://schemas.microsoft.com/.NetConfiguration/v2.0' has invalid child element 'system.we.extensions' in namespace 'http://schemas.microsoft.com/.NetConfiguration/v2.0'. List of possible elements expected: 'system.net' in namespace 'http://schemas.microsoft.com/.NetConfiguration/v2.0'"