Compatibility between the WCF Service and ASMX service in ASP. NET)

Source: Internet
Author: User

Http://webservices.ctocio.com.cn/net/387/9034887.shtml

This article introduces ASP.. NET. NET applications, there are currently two main software technologies that can be used to build services, namely ASMX Web Services and WCF services.

 

Compatibility between the WCF Service and the ASMX Service

According to the previous operation, when a new WCF Service is created for the ASP. net ajax program, the AspNetCompatibilityRequirements attribute is used before the service class by default. Now let's make a brief analysis.

 

  1. [ServiceContract]
  2. [AspNetCompatibilityRequirements (
  3. RequirementsMode = AspNetCompatibilityRequirementsMode. Allowed)]
  4. Public class TimeService
  5. {
  6. ......
  7. }

Although it can be designed for independent transmission, when applied to an ASP. net ajax application environment, the WCF Service can actually work in a way very similar to the ASMX service. With this AspNetCompatibilityRequirements attribute, We can instruct WCF to use the same model as the ASMX service for work. In practice, this setting indicates that when a WCF Service is activated, the declared endpoints will be checked at runtime and the Web HTTP binding model will be used to ensure that all of them are used.

The good compatibility with the ASMX service makes it possible to access ASP. NET objects such as HttpContext objects and other internal ASP. NET objects in the WCF Service.

Note that the compatibility between the WCF Service and the ASMX service must be achieved at least two points. First, in the configuration file web. config, you need to make declaration definitions similar to the following:

 

  1. <System. serviceModel> 
  2. :
  3. <ServiceHostingEnvironmentAspNetCompatibilityEnabled = "true"/> 
  4. </System. serviceModel> 

Second, the developer needs to explicitly select a compatibility mode for the given WCF Service, which is completed by using the service AspNetCompatibilityRequirements attribute.

The service requirements requested in ASP. net ajax applications must be configured on the server. In summary, there are currently two main software technologies in ASP. NET applications that can be used to build services: ASMX Web Services and WCF services. Among them, the WCF Service already includes the ASMX Web service. However, it must be clear that AJAX communication requires the use of JSON data strings for data transmission back and forth between the client and the server. In the era of ASP. net ajax extension 1.0 or ASP. NET 3.5, it is easy to adjust the ASP. NET runtime so that the ASMX Web Service supports JSON. However, for a richer range of WCF services, it is slightly more complex to implement JSON data format transmission. This is why the AJAX backend service can be built using WCF only in ASP. NET 3.5. The above describes the compatibility between the WCF Service and the ASMX service.

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.