Talking about the service of invoking JavaScript in asp.net ajax

Source: Internet
Author: User

Now, you can use the HelloWorldService service as we now use it. Below, I give a relatively clear sample code to complete. The ScriptManager label is also displayed. Note that we have added a clientservicehelper.js file. We placed all the JavaScript functions for client and WCF communications in that file.

<asp:scriptmanager id= "ScriptManager1" runat= "Server" >
<Scripts>
<asp:scriptreference path= "~/script/clientserviceheler.js"/>
</Scripts>
<Services>
<asp:servicereference path= "~/todoservice.svc"/>
</Services>
</asp:ScriptManager>
In the Clientservicehelper.js file section, we used a asp.net AJAX

Client object model to write JavaScript client code.
Type.registerNamespace ("serviceclients");
Serviceclients.todoclient = function () {
}
ServiceClients.ToDoClient.prototype = {
Addtodo:function (Todo, callback, Errorcallback) {
ServiceLibrary.IToDoService.AddToDo (Todo, callback, errorcallback);
},
Deletetodo:function (Todo, callback, Errorcallback) {
ServiceLibrary.IToDoService.DeleteToDo (Todo, callback, errorcallback);
},
Updatetodo:function (Todo, callback, Errorcallback) {
ServiceLibrary.IToDoService.UpdateToDo (Todo, callback, errorcallback);
},
Getalltodo:function (callback, Errorcallback) {
ServiceLibrary.IToDoService.GetAllToDo (callback, Errorcallback);
},
Dispose:function () {
}
}
ServiceClients.ToDoClient.registerClass (' serviceclients.todoclient ', NULL, sys.idisposable)
if (typeof (Sys)!== ' undefined ') Sys.Application.notifyScriptLoaded ();

Summary

In this article, we have learned how to use the AJAX-enabled WCF service item template. Then we learned how to use a service interface based on a WCF service. We also learned how to configure the Web.config file to use the service. Finally, we learned how to add a service reference in ScriptManager. We can also add a service reference to the C # code. The sample code looks like this:

ScriptManager manager = ScriptManager.GetCurrent(Page);
ServiceReference reference = new ServiceReference("ToDoService.svc");
manager.Services.Add(reference);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.