Problem consuming a web service in C# :nullable object must have a value
-
hello! i'm trying to consume a web service writing by a friend in a networking environment.The web service is on the server (main) i tested it there and it is working. the web reference was done withtout a single problem. my code takes data from the request either post or get. to make sure it's working i pass the data that is supposed to be collected by the request object and that one is working to.i also display the value of the querystring passed in my codewith the response.write and is all fine there too.but each time i'm passing the value to the function i see the error Nullable object must have a value. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Nullable object must have a value.
Source Error:
Line 49: // responsemessage = "Dear Customer, bla bla bla";
Line 50: //sendResponse(number, responsemessage);
Line 51: decimal resp = (decimal)serv.getBalance(num, pin);
Line 52: Response.Write(resp);
Line 53: Response.Write(pin);i debug it i they are not null and have the expected value. i'm a lilte bit lost.and have this thing done before night. So i'll to have your opinion. what do you think guys? this are the codes
protected void Page_Load(object sender, EventArgs e) { string text = Request["text"]; string number = Request["number"]; //string responsemessage = ""; string[] t; //decimal resp =0; t = text.Split(new Char[] { ' ',',' }); dreamserve.iWalletMobileBasic serv = new dreamserve.iWalletMobileBasic(); if (t[0].Trim() != "") { if(t[0].ToLower() == "foo") { if(t[1].Trim() !="" && number.Trim()!="") { string num = number.Trim(); string pin = t[1].Trim(); //Response.Write(serv.getBalance(num,pin)); // responsemessage = "Dear Customer,bla bla bla"; decimal resp = (decimal)serv.getBalance(num, pin); Response.Write(resp); } } } }
even if i use number and t[1] directly itsthe same i tough -
hello! i'm trying to consume a web service writing by a friend in a networking environment.The web service is on the server (main) i tested it there and it is working. the web reference was done withtout a single problem. my code takes data from the request either post or get. to make sure it's working i pass the data that is supposed to be collected by the request object and that one is working to.i also display the value of the querystring passed in my codewith the response.write and is all fine there too.but each time i'm passing the value to the function i see the error Nullable object must have a value. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Nullable object must have a value.
Source Error:
Line 49: // responsemessage = "Dear Customer, bla bla bla";
Line 50: //sendResponse(number, responsemessage);
Line 51: decimal resp = (decimal)serv.getBalance(num, pin);
Line 52: Response.Write(resp);
Line 53: Response.Write(pin);i debug it i they are not null and have the expected value. i'm a lilte bit lost.and have this thing done before night. So i'll to have your opinion. what do you think guys? this are the codes
protected void Page_Load(object sender, EventArgs e) { string text = Request["text"]; string number = Request["number"]; //string responsemessage = ""; string[] t; //decimal resp =0; t = text.Split(new Char[] { ' ',',' }); dreamserve.iWalletMobileBasic serv = new dreamserve.iWalletMobileBasic(); if (t[0].Trim() != "") { if(t[0].ToLower() == "foo") { if(t[1].Trim() !="" && number.Trim()!="") { string num = number.Trim(); string pin = t[1].Trim(); //Response.Write(serv.getBalance(num,pin)); // responsemessage = "Dear Customer,bla bla bla"; decimal resp = (decimal)serv.getBalance(num, pin); Response.Write(resp); } } } }
even if i use number and t[1] directly itsthe same i toughhighjo wrote:
(decimal)serv.getBalance(num, pin);
Use decimal.TryParse to convert without it ever blowing up.
highjo wrote:
if (t[0].Trim() != "") { if(t[0].ToLower() == "foo") { if(t[1].Trim() !="" && number.Trim()!="")
Wow - this is messy.
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )