c# - "Object reference not set to an instance of an object" while sending JSON to a webservice using JQuery/AJAX -


edit: after figuring out how step through code appears an exception of type 'system.nullreferenceexception' occurred in datamanagement.dll not handled in user code. happens in line:

string path = httpcontext.current.server.mappath(@"~\desktopmodules\datamanagement\pdf\" + 0 + ".pdf"); 

i'm not sure means sheds more light on problem.

i trying send javascript object web service , getting 500 error: "object reference not set instance of object".

i'm positive passing out of format method in web service i'm not sure. can awesome i'm beginner , have been ramming head against wall on forever.

json (from fiddler):

{"sampleids":["1"],"line1":"","line2":"","line3":"","labeltype":"soil","startinglabelposition":1} 

javascript:

var labelinfo = new object(); labelinfo.sampleids = sampleids; labelinfo.line1 = $('#ddlgrower').val(); labelinfo.line2 = $('#ddlfarm').val(); labelinfo.line3 = $('#ddlfield1').val(); labelinfo.labeltype = $('#ddlsoilloginmatrix option:selected').text(); labelinfo.startinglabelposition = parseint($('#labelselection').text());  $.ajax({     type: "post",     url: "desktopmodules/datamanagement/testservice.svc/createlabelpdf",     data: json.stringify(labelinfo),     contenttype: "application/json; charset=utf-8",     datatype: "json",     success: function(data) {         window.open(data.d);     },     error:  function(msg) {         alert("error: " + msg.status);     } }); 

c# web service:

[operationcontract] public string createlabelpdf(list<string> sampleids, string line1, string line2, string line3, string labeltype, int startinglabelposition) {    list<labelcontent> labels = new list<labelcontent>();     foreach (var sample in sampleids)    {       labelcontent labelcontent = new labelcontent();       labelcontent.line1 = line1;       labelcontent.line2 = line2;       labelcontent.line3 = line3;       labelcontent.labelid = sample;       labels.add(labelcontent);    }        creator creator = new creator    {       includelabelborders = false    };    string path = httpcontext.current.server.mappath(@"~\desktopmodules\datamanagement\pdf\" + 0 + ".pdf");    creator.printlabels(labels, new avery5160(), path, startinglabelposition);    return path; } 

the json seems invalid. think should start with:

{"sampleids":["1"],"line1":"","line2":"","line3":"","labeltype":"soil","startinglabelposition":1} 

right sampleids this:

{"sampleids:["1"],"line1":"","line2":"","line3":"","labeltype":"soil","startinglabelposition":1} 

that is, "sampleids" not formatted key.


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -