简体   繁体   中英

How to add web service layer to web application in ASP.Net

We have an ASP.Net Web Forms application in which we have different folders for Data Access layer objects, Business logic layer objects and presentation layer objects (web forms). We have also implemented Provider model for Sql server. The entire application today is a unified dll file, with the web forms.

We have to now deliver a separate web application which will be accessed as an extranet to this application. We are thinking of implementing it as a presentation layer application with calls to web services (for additional security) rather than connecting to the database directly. We are faced with the following considerations:

  1. Is there a way to use (re-use) the business logic already implemented in the application without copying the source code in a web service component? This would make maintenance more easy since fixing the business logic and data access logic in the application will automatically be effected in the extranet application.

  2. We are using forms authentication today. Is there a way for the extranet application to also use the same user, membership, roles and profile for the extranet, so all users can be administered from the existing application? Will this authentication be treated as a web service?

  1. Yes. You could even try to reference the large *.dll directly, however, it could be advisable to split the large *.dll into smaller ones, following your layers. Data layer first, then the business layer and then the presentation layer. This way, your web service project could reference only the first two.

Another approach would be of course to expose the web service from the very same application that hosts your existing presentation layer.

  1. From the server's perspective, there is no difference between browser's call to a web page and a rich client call to a web service. If you guard your web service with forms authentication, the server will expect a well-formed forms cookie and then, you will be able to access context.User from within the web service code just as you do it in your web app code.

Years ago I've blogged on how to share forms authentication between a web app and a desktop/web service app.

http://www.wiktorzychla.com/2008/02/clickonce-webservice-and-shared-forms.html

Some time later, I've updated the topic with another entry on how to do the same for WCF

http://www.wiktorzychla.com/2010/04/aspnet-forms-authentication-sharing-for.html

This should give you the required background.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM