Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Problem consuming a web service in C# :nullable object must have a value

Problem consuming a web service in C# :nullable object must have a value

Scheduled Pinned Locked Moved ASP.NET
debugginghelpcsharpsysadmindata-structures
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    highjo
    wrote on last edited by
    #1

    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

    C 1 Reply Last reply
    0
    • H highjo

      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

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups