Can I call a webservice from a Controller Action in ASP.Net MVC?
Can I call a webservice from a Controller Action in ASP.Net MVC?
publ开发者_开发技巧ic ActionResult Index()
{
PersonObject person = new Person("Sam");
//Call a webservice which is located in the same app under /Services/General.asmx/WebMethod and pass it person
}
Basically I want to do this from my Action...
$.ajax({
type: "POST",
url: "/Services/General.asmx/WebMethod",
data: JSON.stringify(DTOInternetPricing),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(res) {
},
error: function(res) {
}
});
If the web service is part of the same application you may not need to call it as a web service at all, you could just use it's classes as normal objects, methods, etc. ie just call the logic directly through code.
In order to call a web service in C# you need to generate a client proxy from the WSDL. You need to add a service reference and use the generated proxy to consume the service.
精彩评论