home *** CD-ROM | disk | FTP | other *** search
/ business-86-101-185-173.business.broadband.hu / business-86-101-185-173.business.broadband.hu.zip / business-86-101-185-173.business.broadband.hu / SensorProject.ZIP / SensorService.asmx.cs < prev    next >
Text File  |  2010-10-27  |  2KB  |  57 lines

  1. ∩╗┐using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Services;
  6. using System.Data.SqlClient;
  7. using System.Data;
  8.  
  9. namespace SensorServer
  10. {
  11.     /// <summary>
  12.     /// Summary description for SensorService
  13.     /// </summary>
  14.     [WebService(Namespace = "http://10.146.104.211/")]
  15.     [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
  16.     [System.ComponentModel.ToolboxItem(false)]
  17.     // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
  18.     // [System.Web.Script.Services.ScriptService]
  19.     public class SensorService : System.Web.Services.WebService
  20.     {
  21.  
  22.         [WebMethod]
  23.         public void StoreData(string password, string Value, string SensorID)
  24.         {
  25.             using (SqlConnection con = new SqlConnection(@"server=SQLSERVERNAME;database=TEMPERATUREDB;uid=sensoruser;pwd=X82xrpS1122;"))
  26.             {
  27.                 con.Open();
  28.                 try
  29.                 {
  30.                     using (SqlCommand command = new SqlCommand("StoreTemperatureData", con))
  31.                     {
  32.                         command.CommandType = CommandType.StoredProcedure;
  33.                         SqlParameter prm;
  34.                         prm = new SqlParameter("@password", SqlDbType.VarChar, 17);
  35.                         prm.Value = password;
  36.                         command.Parameters.Add(prm);
  37.                         prm = new SqlParameter("@value", SqlDbType.Decimal);
  38.                         prm.Precision = 5;
  39.                         prm.Scale = 2;
  40.                         prm.Value = Decimal.Parse(Value);
  41.                         command.Parameters.Add(prm);
  42.                         prm = new SqlParameter("@sensorid", SqlDbType.VarChar, 53);
  43.                         prm.Value = SensorID;
  44.                         command.Parameters.Add(prm);
  45.                         command.ExecuteNonQuery();
  46.                     }
  47.                 }
  48.                 catch (Exception ex)
  49.                 {
  50.                     System.IO.File.WriteAllText(@"c:\temp\sensorservice.log", ex.Message);
  51.                     System.IO.File.AppendAllText(@"c:\temp\sensorservice.log", ex.StackTrace);
  52.                 }
  53.             }
  54.         }
  55.     }
  56. }
  57.