Introduction to the JavaScript service called in ASP. NET Ajax

Source: Internet
Author: User

Now, we can use the HelloWorldService as we are currently using. Below, I provide a clear sample code. The ScriptManager label is also displayed. Note that we have added a clientServiceHelper. js file. We placed all JavaScript Functions for client-to-WCF communication 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 section of the clientServiceHelper. js file, we use an 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. policyscriptloaded ();

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 the 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 in the C # code. The sample code is as follows:

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

  1. Use ASP. net ajax to call the WCF Service item Template
  2. How Ajax is implemented in ASP. NET
  3. Use Ajax and Web Service Development instances of ASP. Net 3.5

Related Article

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.