2

I have a webservice in c# and I am calling it from my jquery script.

This is the webservice in c#

[WebMethod]
[ScriptMethod(UseHttpGet = true)]
public void LoadService2Daily(string fromDate, string toDate, string[] campaigns)

In script I do this:

var selectedCampaigns = $("#campaignDiv input:checkbox:checked").map(function () {
        return $(this).val();
    }).get();
    console.log(selectedCampaigns);


webServiceUrl = 'http://localhost:4025/vmp_webservice.asmx/LoadService2Daily';
$.getJSON(webServiceUrl,
      { fromDate: valFrom, toDate: valTo, campaigns: selectedCampaigns })
       .done(function (result) {

I got error 500 and when I check the response, it is Object reference not set to an instance of an object.

Note

If I removed the string[] array from the web service, it works perfectly, but when I add it, it stoped working. so I am sure it is because the string array thing but I don't know where exactly is the mistake.

The code without the array have been working for 3 years without any problem, but now I am making some editing and I need to pass that array.

This is a screenshot of the console.log to print the selectedCampgains. Notice that, as I showed you in the code, this log is taken before calling the web service

enter image description here

Edit

I noticed that the url of the web service is

Request URL:http://localhost:4025/vmp_webservice.asmx/LoadService2Daily?fromDate=2014-05-25+00%3A00%3A00&toDate=2014-05-25+23%3A59%3A01&campaigns%5B%5D=default&campaigns%5B%5D=Support

as it doesn't contain the string array, right?

Edit3

This is the whole exception that I get

System.NullReferenceException: Object reference not set to an instance of an object.
   at System.Web.Services.Protocols.ValueCollectionParameterReader.Read(NameValueCollection collection)
   at System.Web.Services.Protocols.UrlParameterReader.Read(HttpRequest request)
   at System.Web.Services.Protocols.HttpServerProtocol.ReadParameters()
   at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()
15
  • 1
    stackoverflow.com/questions/4660142/… Commented May 25, 2014 at 18:22
  • 1
    @SonerGönül it is not a null exception, the main problem is the 500 error. Commented May 25, 2014 at 18:37
  • Have you set a breakpoint and stepped through the code of the webservice to find out exactly where the error is being raised? Commented May 25, 2014 at 18:40
  • @RoryMcCrossan yes I already did that. but no break point executes which indicates that the web service is not called at all. I think that I am calling it wrong. right? Commented May 25, 2014 at 18:44
  • 1
    There is a lot going on in the selectedCampaigns variable. What is the result of the selectedCampaigns before you pass it into the server side method? Use a browser debugger to take a peek at the info. Consider something like fiddler as well to see what message is being passed to the server Commented May 25, 2014 at 18:45

1 Answer 1

1

The URL which is being generated has square brackets, can you please check whether this will work without square brackets i.e without %5B and %5D(without url encoding)

http://localhost:4025/vmp_webservice.asmx/LoadService2Daily?fromDate=2014-05-25+00%3A00%3A00&toDate=2014-05-25+23%3A59%3A01&campaigns=default&campaigns=Support
Sign up to request clarification or add additional context in comments.

4 Comments

please tell me what did you do and how to fix the problem, you maject url works, but what should I do in my request to avoid these stuff that you have removed ?
please give me an example, I really don't know.
I will accept your answer now, +1 please could u complete your answer in my this new question about the same thing stackoverflow.com/questions/23859946/…
OK I'll be doing that for you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.