Cis Pa

Cis Pa

  • NA
  • 194
  • 22.9k

how to consume Stored Procedure REST WEB service in Client application

Jun 5 2021 9:43 AM

Hi all,

I have created stored procedure REST Web service in ASP.net .i tested in POSTMAN  and seems working fine. I want to return value as 1in my client application.But i dont know how to consume REST web service in WPF windows application . 

Please help.

REST web api code :

[HttpGet]
public IHttpActionResult StartOnline(string SName)
{
int ReturnValue = 0;
SqlCommand cmd = new SqlCommand("StartOnline", con);
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
SqlParameter ret = new SqlParameter();
ret.Direction = ParameterDirection.ReturnValue;
cmd.Parameters.AddWithValue("@SName", SName);
ret.Direction = ParameterDirection.ReturnValue;
cmd.Parameters.Add(ret);
cmd.ExecuteNonQuery();
try
{
con.Open();
cmd.ExecuteNonQuery();
con.Close();
ReturnValue = (int)ret.Value;
}
catch (Exception ex)
{
}
return Ok(ReturnValue);
}

Tried in my windows application 

var client = new HttpClient();
client.BaseAddress= new Uri("http://localhost/RestWebAPI/");
var responseString = await client.GetStringAsync("api/Start/SStart");

Getting error as

 
{StatusCode: 404, ReasonPhrase: 'Not Found', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
X-SourceFiles: =?UTF-8?B?RTpcV2ViIFNlcnZpY2VcUkVTVFdlYlNlcnZpY2VTUFxSRVNUV2ViU2VydmljZVNQXGFwaVxTdGFydFxERFNTdG9wXEREUyAx?=
Cache-Control: private
Date: Fri, 04 Jun 2021 08:53:06 GMT
Server: Microsoft-IIS/10.0
X-Powered-By: ASP.NET
Content-Length: 4814
Content-Type: text/html; charset=utf-8
}}

 

 


Answers (1)