I need to implement syncing accounting items to cloud,so I have already WCF methods to sync but I want web API to post json data and then it store in web DB.
like earlier we made a get method for android application and return data in json format.
Code
[AcceptVerbs("Get")]Code
public DataTable Inflow(long TenantId, long SalesPersonId)Code
{Code
DataTable dtReceivable = new DataTable(); return dtReceivableCode
}MyURL/api/MobileAPI/Inflow?TenantId=1234&SalesPersonId=22
and then getting data in json format
Now I want to create a Post Method for syncing with web DB.
Code
string JsonString = Inventory();I want to post this via my URL like
using (HttpClient httpclient = new HttpClient())
{
string url = "http://localhost:51411/api/MobileAPI/Inventory?TenantId=" + CommonClass.tenantId + "";
String uriToCall = String.Format(url);
var content = new FormUrlEncodedContent(new[]
{
new KeyValuePair("", str)
});
}
I am not getting how to start so please can anyone can help me.
I tried this by reading some google articles but still its not fine....
string str = Inventory();
//HttpClient http = new HttpClient();
using (HttpClient httpclient = new HttpClient())
{
var http = (HttpWebRequest)WebRequest.Create(new Uri("http://localhost:51411/api/MobileAPI/Inventory?TenantId='" + CommonClass.tenantId + "'&JsonInventory='" + str));
http.Accept = "application/json";
http.ContentType = "application/json";
http.Method = "POST";
}
and my web API code is
[HttpPost]
[AcceptVerbs("POST")]
public HttpResponseMessage Inventory(long TanantId, [FromBody]string JsonInventory)
{
try
{
List lstInventory = JsonConvert.DeserializeObject
- >(JsonInventory);
foreach (var item in lstInventory)
{
}
return new HttpResponseMessage(HttpStatusCode.OK);
}
catch (Exception ex)
{
throw ex;
}
}
My Inventory Model is this
Code
public class InventoryCode
{Code
public string ItemId { get; set; }Code
public string Category { get; set; }Code
public decimal Price1 { get; set; }Code
public string Description { get; set; }Code
public int QuantityAvailable { get; set; }Code
public int QuantityOnHand { get; set; }Code
public string Method { get; set; }Code
}please help me how to call url then during calling my break point hit


Robert Raboud46 reputationPosted Jun 9, 2017, 5:18 AM EDT