Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is my WebMethod
VB
<WebMethod(Description:="Fetch Nested Albums", EnableSession:=True)> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _
Public Function moveImages() As Object
    Dim FileCount As Integer = _
        HttpContext.Current.Request.Form(
            HttpContext.Current.Request.Form.Count - 2)
End Function

When i try to call the web service from the .aspx page i get this error

"Index was out of range. Must be non negative and less than the size of the collection."

How can i access the request Object? I was not able to access the session object in the web method, so i had to add EnableSession:=True in the Web Method.

So is there any setting for the request Object too?
Posted

1 solution

Hi,

I see this line:
VB
Dim FileCount As Integer =
        HttpContext.Current.Request.Form(
            HttpContext.Current.Request.Form.Count - 2)

If HttpContext.Current.Request.Form.Count is less than 2, then you try to take a form variable at place -1 (or -2, -3, ...).
 
Share this answer
 
Comments
Member 7781963 14-Dec-12 8:42am    
Is there something wrong?
Thomas Daniels 14-Dec-12 8:43am    
I think HttpContext.Current.Request.Form.Count is less then 2.
Member 7781963 14-Dec-12 8:50am    
Actually when i execute the same code on a button click in the page code behind, it works.
Thomas Daniels 14-Dec-12 8:54am    
Sometimes, there're more than 2 form variables.
Sometimes, there're less than 2 form variables.
Member 7781963 14-Dec-12 9:04am    
actually the main reason i am trying to do it in a web method is to avoid post back..any way i can do it in a button click in the code behind without the post back?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900