In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
How to understand the WCF services of ASP.NET applications? in view of this problem, this article introduces the corresponding analysis and solutions in detail, hoping to help more partners who want to solve this problem to find a more simple and easy way.
ASP.NET applications add WCF services
Now, let's learn how to add an AJAX-enabled WCF service to the previous ASP.NET site. To do this, right-click the sample website AJAXWCFTest1 above and select "Add New Items …" Select the "AJAX-Enabled WCF Service" template in the Add New Items dialog box that appears to add a new WCF service and name it TimeService.
After doing the above, you will find that a service endpoint (that is, timeservice.svc) has been added to the Web website and the associated Code-behind file timeservice.cs located in the folder App_Code. In addition, notice that the configuration file web.config has also been modified to provide appropriate registration and discovery information for the WCF service you just created.
The contract of the defined WCF service and its explicit implementation are implicitly described in the TimeService class that is now created. Note that the ServiceContract and OperationContract attributes assume the same role as in previous versions of WCF programming. In addition, for the sake of simplicity, no interface definition contract is used here.
Using System; using System.Runtime.Serialization; using System.ServiceModel; using System.ServiceModel.Activation; using System.ServiceModel.Web; [ServiceContract (Namespace = "Samples.Services")] [AspNetCompatibilityRequirements (RequirementsMode=AspNetCompatibilityRequirementsMode.Allowed)] public class TimeService. {[OperationContract] public DateTime GetTime (). {return DateTime.Now;} [OperationContract] public string GetTimeFormat (string format). {return DateTime.Now.ToString (format);}}
Notice that the above TimeService class exposes two common endpoints, GetTime and GetTimeFormat.
The endpoint that reaches the method in the above interface is defined in an SVC file. The contents of the file timeservice.svc are shown below:
The service host (ServiceHost) indicates the language used to implement the service and the location of the corresponding source file, and * identifies the contract name used by the Service attribute.
Before officially testing the service, another task is to register the above WCF service in the configuration file web.config of the host ASP.NET application. The contents of the relevant configuration section in the configuration file web.config are shown below:
Note that the above configuration is automatically generated by the system with the creation of the WCF service.
Here, first register a behavior list for all endpoints in the previous WCF service. In this way, a behavior is defined for the WCF service TimeServiceAspNetAjaxBehavior and indicates that it uses client script to accept requests via the HTTP Web protocol. Logically, the above enableWebScript element is consistent with the ScriptService attribute used to decorate the Web service class in the ASP.NET Web service.
Then, you need to enumerate all the WCF services hosted in the current ASP.NET application. Notice that only one service named TimeService is shown in the web.config file above, and one of its endpoints uses the TimeService contract and the webHttpBinding binding model.
This is the answer to the question about how to understand the WCF service of ASP.NET application. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.
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.