I have a web service setup on my pc, and i have used SOAP to communicate between them and it worked fine. Now i want to change the data exchange type to JSON from xml, but i dont know how to invoke the method using Http and json.
Web Service Setup is something like this
[WebService(Namespace = "https://webapplication4-mv3.conveyor.cloud/")]
[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
{
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public void Login(string username, string password)
{
JavaScriptSerializer js = new JavaScriptSerializer();
if(username == "Selman" && password == "123456")
{
Context.Response.Write("Access Granted");
}
else
{
Context.Response.Write("Access Denied");
}
}
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public void GetStudents()
{
Students[] students = new Students[2]
{
new Students()
{
StudentId = 1,
Name = "NitinTyagi",
Marks = 400
},
new Students()
{
StudentId = 2,
Name = "AshishTripathi",
Marks = 500
},
};
JavaScriptSerializer js = new JavaScriptSerializer();
Context.Response.Write(js.Serialize(students));
}
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string GetAllMethodNamesAndInputTypes()
{
return "Hello World";
}
[WebMethod]
public int Multiplication(int a, int b)
{
return (a * b);
}
[WebMethod]
public string GetClientData(int Number)
{
ClientData[] Clients = null;
Clients = new ClientData[Number];
for (int i = 0; i < Number; i++)
{
Clients[i].Name = "Client " + i.ToString();
Clients[i].ID = i;
}
string tempString = "";
tempString += "Start Of Document\n\n";
for( int i = 0;i<Number;i++)
{
tempString += "Client Name is : " + Clients[i].Name + "\n";
tempString += "Client ID is : " +Clients[i].ID + "\n";
}
tempString+= "\n\n End Of Document";
return tempString;
}
}
public class Students
{
public int StudentId
{
get;
set;
}
public string Name
{
get;
set;
}
public int Marks
{
get;
set;
}
}
public struct ClientData
{
public String Name;
public int ID;
}
}
My question is, where to put method names and parameters, if it is even possible using HTTP instead of SOAP?
(I am trying to access the web service from an Android Phone using kotlin)
Aucun commentaire:
Enregistrer un commentaire