In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces ASP.NET AJAX's WCF service to you, the content is very detailed, interested friends can refer to, hope to be helpful to you.
Now we will learn more about the traditional WCF service implementation, and we will also learn how to expose the service through ASP.NET AJAX. By default, when we create a class library project, we do not add a service model and run-time serialization support for the WCF system that needs to be run. Therefore, we have to add the necessary service references.
Continue and click the right mouse button of the class library project, then select add reference, and then select the following reference:
◆ System.Runtime.Serialization
◆ System.ServiceModel
In this phase, we will use a TODO management example to demonstrate the entire process. Add a database-based service and create a standard Todo with fields ID, Description, and Status. Now, add a class file for LINQ to SQL from the project template. Drag and drop the TODO table from the database onto the LINQ to SQL class file designer.
Now add the designer surface and change the serialization mode to one-way from the properties window. Now our designer has generated LINQ to SQL classes that can be used by WCF. If you want to use custom user-defined types, you must set the [DataContract] attribute for your class and you must add [DataMember] attribute to each property of the WCF service class you want to expose.
Now, we will add a service interface in the following form:
NamespaceServiceLibrary {[ServiceContract (Namespace= "ServiceLibrary")] interfaceIToDoService {[OperationContract] ToDoGetToDo (longID); [OperationContract] ToDoAddToDo (ToDotoDo); [OperationContract] boolDeleteToDo (ToDotodo); [OperationContract] ToDoUpdateToDo (ToDotodo); [OperationContract] ListGetAllToDo ();}}
Notice a namespace that we have already mentioned in the ServiceContract interface feature. This is very important. We will use this name as the name of the service for internal JavaScript code to access the service. Now, we will add the interface that implements the service; the code is as follows.
Note the [AspNetCompatibilityRequirements (RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] feature used in the code for class properties; this is necessary to enable WCF service exposure with ASP.NET AJAX.
NamespaceServiceLibrary {[AspNetCompatibilityRequirements (RequirementsMode= AspNetCompatibilityRequirementsMode.Allowed)] publicclassToDoService:IToDoService {# regionIToDoServiceMembers publicToDoGetToDo (longID) {DataClasses1DataContextcontext=newDataClasses1DataContext (); vartoDos=frompincontext.ToDos wherep.ID==ID selectp; ListlistTodos=toDos.ToList (); if (listTodos.Count > 0) {returnlistTodos [0];} else {returnnull }} # endregion}} this is the end of the WCF service about ASP.NET AJAX. I hope the above content can be helpful to you and learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.