Reputation: 8188
I am making wcf calls and getting back data in my application via this javascript code..
function setCurrentResponseValue(response) {
var applicationData = null;
$.ajax({
type: "POST",
url: "ClientService.svc/REST/SetCurrentResponseValue",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({ response: response }),
dataType: "json",
async: false,
success: function (msg) {
applicationData = msg;
},
error: 'An Error'
});
return applicationData;
}
I need to set session variables my svc file uses from C# code behind. How do I call a method in my svc file from code behind instead the ajax call above?
Upvotes: 0
Views: 2387
Reputation: 11284
There are lots of very similar questions already on SO. This has perhaps the best answers: How to Consume a Restful Service in .NET?
@Darrel Miller's answer is probably the most useful there, with a link to his blog post showing how to use HttpClient to consume REST data: http://www.bizcoder.com/index.php/2012/01/09/httpclient-it-lives-and-it-is-glorious/
(The fact that the service is WCF is largely irrelevant to the client if you're using loose coupling against REST).
Upvotes: 1