How to creating web service? [Resolved]

Posted by Ssagard under C# on 5/9/2016 | Points: 10 | Views : 546 | Status : [Member] | Replies : 3
From web API we receive data in json format. We have to store that data in our db every 10 min using c# .net




Responses

Posted by: A2H on: 5/9/2016 [Member] [MVP] Bronze | Points: 50

Up
0
Down

Resolved
To call the function on every 10 mins you can use the below code

window.onload = function () {
SubmitData();
setTimeout( SubmitData(), 600000);
}


Thanks,
A2H
Please mark my reply as answer if it helps to resolve your problem

Ssagard, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: A2H on: 5/9/2016 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Since you have WebApi to fetch the data then IMHO creating a webservice just to submit the data is not needed. Unless there is a valid reason you can use WebApi itself to push the value.

Sample Implementation

Sample Class(You can create this as per your design like a Customer, Employee etc

 public class SampleClass
{
public string Empname { get; set; }
}


Now add a Post method to your controller
public class SampleController : ApiController
{
[HttpPost]
public void PostData(SampleClass sampleClass)
{

}
}


To call this function from Aspx page you can use Jquery Ajax or Angular or any similar option available. I have used Jquery ajax

<script>
//Get the Json value
//Here you need to have the WebApi call get the results
var SampleJsonValue = { Empname: "SampleJsonValue" };
function SubmitData() {
$.ajax({
type: 'POST',
//Here change the path(Method name and controller name) accordingly
url: '/api/Sample/PostData',
data: JSON.stringify(SampleJsonValue),
contentType: 'application/json; charset=utf-8',
dataType: 'json'
});
}
</script>





Thanks,
A2H
Please mark my reply as answer if it helps to resolve your problem

Ssagard, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayden on: 6/16/2016 [Member] Starter | Points: 25

Login to post response