简体   繁体   中英

ASP.NET Web Service Application vs ASP.NET Web Service

I am a newbie in .NET. Today I am learning about Web Service. I found two ways of creating a web service.

First one is - Right click on Solution << Add New Project << ASP.NET Web Service Application

Second one is - Right click on Solution << Add New Web Site << ASP.NET Web Service

What is the difference between them?

The Web Service Application precompiles all of your code into a singe.dll that will be placed in the bin. So if you have several web service files and code in each one of them, they will all be compiled into a common dll. This library will be loaded each time any of the services is called.

The web service website will keep the code files in the App_Code directory and each service will have its own code compiled into its own separated library within the Temporary Asp.Net files folder. This allows for each library to be loaded independently into memory.

They both have their advantages and disadvantages. The single library is easier to move/update than the website model, but the website model allows for segregation of memory usage preventing a problem in one service from affecting a separate service.

Edit:

What I mean by segregation of memory usage is that each.dll is loaded dependent on the processes necessary to complete the transaction. The w3wp.exe process which controls the threads will spool up the individual.dlls as necessary to complete the request/response. In an application, these.dlls never change. They are all loaded with the process whether they are needed or not. In a website, each page or service is compiled as a separate library. So if w3wp.exe needs to load App_Code/MyService_as33fweqs.dll (the dynamically generated temporary name of the compiled dll) to complete a task, it is smaller and potentially faster because it only carries with it what it needs. This allows w3wp.exe to generate threads of varying complexity/memory needs independently.

You should not use either of those. They use the legacy "ASMX" technology. All new service development should be in WCF.

Use "WCF Service Application" or "WCF Service Library", or one of the more specific versions.

I also recommend against ever using "New Web Site". That's a mistake Microsoft made in the process of trying to accommodate people used to PHP and similar technologies. It is different from every other kind of .NET project, and behaves in ways nobody else would ever expect. There is very little reason to use it for anything non-trivial.

BTW, I consider web services to be non-trivial, so would never use a web site "project" for web services.

In ASP.NET, the term 'application' implies it is pre-compiled, whereas 'site' implies it is not. I would opt for the former.

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