2010-10-27 64 views
-1

我可以從ASP.Net MVC中的Controller Action調用webservice嗎?我可以從ASP.Net MVC中的Controller Action調用webservice嗎?

public 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 
} 

基本上我想從我的行動做到這一點...

   $.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) { 
        } 
       }); 
+0

什麼樣的網絡服務?你的意思是你的控制器操作是你的網絡服務?你是從哪裏來的? – 2010-10-27 04:06:02

+0

更新我的問題.. – Jason 2010-10-27 04:20:31

回答

2

如果Web服務是你可能不需要它在所有調用的Web服務的同一應用程序的一部分,你可以將它的類作爲普通對象,方法等使用,即直接通過代碼調用邏輯。

2

爲了在C#中調用Web服務,您需要從WSDL生成一個客戶端代理。您需要add a service reference並使用生成的代理來使用該服務。

相關問題