using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Script.Serialization;
using System.Collections;
namespace SampleWS
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class WebService1 : System.Web.Services.WebService
{
DataClasses1DataContext DB = new DataClasses1DataContext();
[WebMethod]
public String Registration(String G_name,String T_name,String password)
{
Guide guide = new Guide();
guide.G_name = G_name;
guide.T_name = T_name;
guide.Password = password;
DB.Guides.InsertOnSubmit(guide);
try
{
DB.SubmitChanges();
}
catch
{
return "fail";
}
return "success";
}
[WebMethod]
public String update(String T_name,String vehicalinfo,String Charges,String More,String phone,String email,String contactExtra)
{
var r2 = DB.Guides
.Where(w => w.T_name == T_name)
.SingleOrDefault();
if (r2 != null)
{
r2.VehicleInfo = vehicalinfo;
r2.ContactInfo = contactExtra;
r2.More = More;
r2.Phone = phone;
r2.email = email;
DB.Guides.InsertOnSubmit(r2);
try
{
DB.SubmitChanges();
}
catch
{
return "fail";
}
}
else
{
return "fail";
}
return "success";
}
[WebMethod]
public String updatelatlon(String lat, String lon)
{
Guide guide = new Guide();
guide.Lat = lat;
guide.@long = lon;
DB.Guides.InsertOnSubmit(guide);
try
{
DB.SubmitChanges();
}
catch
{
return "faile";
}
return "success";
}
[WebMethod]
public
void getAllLocation()
{
ArrayList parent = new ArrayList();
var query = from guide in DB.Guides
select guide;
foreach (var gud in query)
{
Dictionary<string, string> dictionary = new Dictionary<string, string>();
dictionary.Add("lat", gud.Lat);
dictionary.Add("log", gud.@long);
parent.Add(dictionary);
}
JavaScriptSerializer serializer = new JavaScriptSerializer();
string json = serializer.Serialize(parent);
Context.Response.Write(json);
///return json;
}
[WebMethod]
public String gettravelinfo(String T_name)
{
return "success";
}
}
}
==============================
[WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public void MyMethod(... params ...)
{
try
{
var retval = new JavaScriptSerializer()
.Serialize(new MyObject());
Context.Response.Write(retval);
}
catch (Exception ex)
{
Context.Response.Write(string.Format("[ERROR: {0}]", ex.Message));
}
}