There is a javascript code, a fragment of the class method:

var formData = new FormData(); formData.append("lat", this.LatLng.lat); var xhr = new XMLHttpRequest(); xhr.open("POST", "/MyDbService.asmx/MyDbMethod", true); xhr.send(formData); 

Fragment of the web service MyDbMethod method:

 string request_lat = Context.Request.Params["lat"]; bd.WriteToLog("request_lat = " + request_lat); double lat = double.Parse(request_lat, CultureInfo.InvariantCulture); bd.WriteToLog("lat = " + lat); 

I check the received data on the web service side, writing a log to a text file, in a javascript I output to the console.

The lat parameter is successfully transmitted to the server, first read into the request_lat variable, and then already in the lat status it is also successfully written to the log. However, the response from the server comes as follows:

 `System.ArgumentNullException:` Значение не может быть неопределенным. Имя параметра: `value` в `System.Number.ParseDouble(String value, NumberStyles options, NumberFormatInfo numfmt)` в `System.Double.Parse(String s, IFormatProvider provider)` в `MyDbService.MyDbMethod() в <...>MyDbService.asmx.cs:`строка 107 

Line 107 contains the double.Parse method double.Parse .

What could be the problem?

Update

I know about the presence of an exception in the browser console. The web service method continues to work after line 107, writing to the database is successful (I Context.Response.Write testing now without writing), the data recorded via Context.Response.Write are successfully transferred to the browser. The browser writes to the console "incorrectly" and when you click on the link in the new window opens a message about the exception.

  • So what is written to the log in line 106? When writing to the log, it is better to surround the value with brackets or quotes so that spaces at the beginning and at the end are visible. - nzeemin
  • I forgot to specify, here are the lines from the log: request_lat = 59.936526419625935 lat = 59.9365264196259 - Ponio
  • It's very strange that the second WriteToLog () worked - in line 108 - you had an exception in line 107. I suspect that sometimes a value comes from javascript to the server, and sometimes it doesn't. - nzeemin
  • Supplemented by the main message, not only the second method WriteToLog () works, but everything below. I also had such suspicions, but everything that came is written to the log. It also went through all the parameters in the foreach loop, it was logged all the same as it was sent from javascript. - Ponio
  • Another embarrassing way of getting a parameter of a web method: Context.Request.Params["lat"] - why not declare it as a parameter of the method explicitly? - nzeemin

1 answer 1

Try logging in more detail and checking the correctness of the incoming value (this is useful anyway):

 string request_lat = Context.Request.Params["lat"]; bd.WriteToLog("request_lat = " + request_lat); double lat; if (string.IsNullOrEmpty(request_lat) bd.WriteToLog("lat is null or empty"); else if (!double.TryParse(request_lat, out lat)) bd.WriteToLog("failed to parse lat value"); else bd.WriteToLog("lat = " + lat); 
  • followed your advice by adding <code> string request_lat_2 = request_lat.Replace ('.', ','); </ code> and <code>! double.TryParse (request_lat_2, out lat) </ code>. The result is the same, positive. By the way, I checked in the Opera - no reports of exception. Everything described previously applies to Firefox. The fact is that when transferring a website to a hosting service, this function of the web service stopped working, then this hidden exception was discovered, although it may not be the reason for the website failure on the hosting. - Ponio