我在PC上安装了Web服务,并且使用SOAP在它们之间进行通信,并且运行良好。现在我想将数据交换类型从xml更改为JSON,但我不知道如何使用Http和json调用该方法。
Web服务设置是这样的
[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;
}
}
我的问题是,如果甚至可以使用HTTP而不是SOAP,在哪里放置方法名称和参数?
(我正在尝试使用kotlin从Android手机访问网络服务)