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
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()