asp.net-mvcajaxweb-services

Ajax (calling web service) with MVC


I have an asp.net mvc application and i need to to use ajax in this application , i need to add a scriptmanager and add a service refrences with the path of a web service and then call the web service from tag . I have the following code and it doesn't see the web service :

<form>
<input id="SubmitBtn" type="button" value="Sumbit" onclick="TestService(); return false;" />
   <asp:ScriptManager ID="ScriptManager1" runat="server">
    <Services>
        <asp:ServiceReference Path="~/MVCService.asmx" />
    </Services>
    </asp:ScriptManager> 
<script type="text/javascript" language="javascript">  
    function TestService()
    {
        alert('Welcome');
        var ret = MVCService.HelloWorld(OnCheckComplete,OnFailed,OnTimeOut);
    }
    function OnCheckComplete(arg)
    {
         alert(arg);
    }
    function OnFailed(arg)
    {
        alert(arg);
    }
    function OnTimeOut(arg)
    {
        alert(arg);
    }
     </script>
</form>

And it reports an error say : MVCService is undefined so how can i solve this problem ? do i need specific configuration in the MVC application to solve this problem ? I have add ajax toolkit dll to my application refrences and the problem still exist

Thanks in advance


Solution

  • Thanks every one i have found the soltuion for the problem at the folloiwng link : Ajax with asp.net mvc

    The following part solved my problem:

    <script type="text/javascript" src="../../Content/MicrosoftAjax.debug.js"></script>
    <script type="text/javascript">   
    function TestService() 
    {  
       Sys.Net.WebServiceProxy.invoke("../../Services/MVCService.asmx","HellowWord", false,null, success, fail );
    }
    </script>