如何使用webservice
C#
我有以下有关webservice
BASE_URL
是托管URL
的{{1}}。然后,此WebServices
后跟所需的BASE_URL
名称,然后是所需的GROUP
名称。
例如,
METHOD
这将提供完整的URL:
BASE_URL = https://www.abcd.com/ws/
GROUP = transaction
METHOD = createTransaction
每次调用都必须包含以下参数(作为POST变量):
https://www.abcd.com/ws/transaction/createTransaction
请帮我一些链接来实现编码。
答案 0 :(得分:0)
您可以使用HttpClient课程。
static async void Main()
{
try
{
// Create a New HttpClient object.
HttpClient client = new HttpClient();
HttpResponseMessage response = await client.PostAsync("https://www.abcd.com/ws/transaction/createTransaction");
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();
// Above three lines can be replaced with new helper method in following line
// string body = await client.GetStringAsync(uri);
Console.WriteLine(responseBody);
}
catch(HttpRequestException e)
{
Console.WriteLine("\nException Caught!");
Console.WriteLine("Message :{0} ",e.Message);
}
}
这不完整,您必须将参数传递给HttpContent对象格式的PostAsync方法。
答案 1 :(得分:0)
这是在asp.net中调用或使用rest webservice的一种技术c
var client = new RestClient("url");
var request = new RestRequest(Method.POST);
request.AddHeader("content-type", "application/json");
request.AddParameter("application/x-www-form-urlencoded","type=password&user_id=test@gmail.com",ParameterType.RequestBody);
IRestResponse response = client.Execute(request);