Microsoft enterprise database 5.0 Study Notes (11) WCF and ASP. NET web service applications

Source: Internet
Author: User

To initialize the container and populate the dependencies of a Web service application, you must expose user interfaces (such as Windows Forms, WPF, and ASP. NET web forms) in different methods of the application type ). This topic describes possible solutions and resources for ASP. NET web services (asmx), and helps you implement them in WCF applications.

ASP. NET Web Service Application

ASP. NET web service applications can partially use methods in the topic ASP. NET web forms application. You can add the extension method of httpapplicationstate to create and publish containers, and add the code to the Global. asax file of the application to add the Enterprise Library extension to the container. However, because there are no UI controls in asmx applications, you cannot use the HTTP module as described in ASP. NET web forms applications.

However, you can call the httpcontext. Current. application. getcontainer () Extension Method to access the container. You can useBuildupThe method fills in the dependencies you define through Properties.For example, the following code uses dependency injection to solve the problemImyserviceAnd use it to calculateUsedataserviceValue returned by the method.

 

Using system. web; </P> <p> public class mywebservice: system. web. services. webService <br/>{< br/> private imyservice theservice; </P> <p> Public mywebservice () <br/>{< br/> // pass this class through the container using the buildup method <br/> httpcontext. current. application. getcontainer (). buildup (this ); <br/>}</P> <p> [dependency] <br/> Public imyservice dataservice <br/>{< br/> get {return theservice ;} <br/> set {theservice = value ;}< br/>}</P> <p> [webmethod] <br/> Public String usedataservice () <br/>{< br/> return "the value you require is" + theservice. dosomething (); <br/>}< br/>

 

 

 

You can use the basic methods displayed in the ASP. NET web forms application to create and assembleApplicationThe container in the dictionary object, and then access it through your web method when necessary.

WCF Application

In WCF, you can use technologies similar to the basic principles described in this topic. However, there is no stored httpapplication status in WCF. Instead, you can useInstancecontextmodeOfInstancecontextIt is set as a singleton and applies to all requests. You must implementIextensionInterfaceInstancecontextCustom extension.

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.