简体   繁体   English

c#jquery对象引用未设置为对象的实例

[英]c# jquery Object reference not set to an instance of an object

I have a webservice in c# and I am calling it from my jquery script. 我在C#中有一个Web服务,我从我的jquery脚本中调用它。

This is the webservice in c# 这是C#中的Web服务

[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. 我收到错误500 ,当我检查响应时,它是未设置为对象实例的对象引用。

Note 注意

If I removed the string[] array from the web service, it works perfectly, but when I add it, it stoped working. 如果我从Web服务中删除了string[] array ,则它可以正常工作,但是当我添加它时,它就停止了工作。 so I am sure it is because the string array thing but I don't know where exactly is the mistake. 所以我确定这是因为string array但是我不知道错误在哪里。

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. 没有数组的代码已经运行了3年,没有任何问题,但是现在我要进行一些编辑,我需要传递该数组。

This is a screenshot of the console.log to print the selectedCampgains. 这是console.log的屏幕截图,用于打印选定的console.log Notice that, as I showed you in the code, this log is taken before calling the web service 请注意,正如我在代码中向您展示的那样,该日志是在调用Web服务之前获取的

在此处输入图片说明

Edit 编辑

I noticed that the url of the web service is 我注意到该Web服务的网址是

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 编辑3

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

正在生成的网址带有方括号,您能否检查如果没有方括号即没有%5B和%5D(没有url编码)是否可以正常使用

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM