开发者

Can I call a webservice from a Controller Action in ASP.Net MVC?

开发者 https://www.devze.com 2023-01-21 08:19 出处:网络
Can I call a webservice from a Controller Action in ASP.Net MVC? publ开发者_开发技巧ic ActionResult Index()

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消