简体   繁体   English

ASP.NET Web 服务应用 vs ASP.NET ZC6E190B284633C48E39E55049DA3CCE8

[英]ASP.NET Web Service Application vs ASP.NET Web Service

I am a newbie in .NET.我是 .NET 的新手。 Today I am learning about Web Service.今天学习Web服务。 I found two ways of creating a web service.我找到了两种创建 web 服务的方法。

First one is - Right click on Solution << Add New Project << ASP.NET Web Service Application第一个是- 右键单击解决方案 << 添加新项目 << ASP.NET Web 服务应用程序

Second one is - Right click on Solution << Add New Web Site << ASP.NET Web Service第二个是-右键单击解决方案<<添加新的Web站点<< ASP.NET Web服务

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. Web 服务应用程序将您的所有代码预编译成一个单独的.dll,该文件将被放置在 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.所以如果你有几个 web 服务文件和代码,它们都将被编译成一个通用的 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. web 服务网站将代码文件保存在 App_Code 目录中,每个服务都将自己的代码编译到临时 Asp.Net 文件夹中自己的独立库中。 This allows for each library to be loaded independently into memory.这允许将每个库独立加载到 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.单个库比网站 model 更容易移动/更新,但网站 model 允许隔离 memory 的使用,从而防止一个服务中的问题影响单独的服务。

Edit:编辑:

What I mean by segregation of memory usage is that each.dll is loaded dependent on the processes necessary to complete the transaction.我所说的 memory 使用隔离的意思是 each.dll 的加载取决于完成交易所需的流程。 The w3wp.exe process which controls the threads will spool up the individual.dlls as necessary to complete the request/response.控制线程的 w3wp.exe 进程将在必要时假脱机处理 individual.dll 以完成请求/响应。 In an application, these.dlls never change.在应用程序中,这些.dll 永远不会改变。 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.因此,如果 w3wp.exe 需要加载App_Code/MyService_as33fweqs.dll (已编译 dll 的动态生成的临时名称)来完成任务,它会更小并且可能更快,因为它只携带它需要的东西。 This allows w3wp.exe to generate threads of varying complexity/memory needs independently.这允许 w3wp.exe 独立生成不同复杂度/内存需求的线程。

You should not use either of those.你不应该使用其中任何一个。 They use the legacy "ASMX" technology.他们使用传统的“ASMX”技术。 All new service development should be in WCF.所有新的服务开发都应该在 WCF 中。

Use "WCF Service Application" or "WCF Service Library", or one of the more specific versions.使用“WCF 服务应用程序”或“WCF 服务库”,或更具体的版本之一。

I also recommend against ever using "New Web Site".我还建议不要使用“新 Web 站点”。 That's a mistake Microsoft made in the process of trying to accommodate people used to PHP and similar technologies.这是微软在试图适应习惯于 PHP 和类似技术的人们的过程中犯的一个错误。 It is different from every other kind of .NET project, and behaves in ways nobody else would ever expect.它不同于其他所有类型的 .NET 项目,并且其行为方式是其他人无法预料的。 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.顺便说一句,我认为 web 服务并不重要,因此永远不会为 web 服务使用 web 站点“项目”。

In ASP.NET, the term 'application' implies it is pre-compiled, whereas 'site' implies it is not.在 ASP.NET 中,术语“应用程序”意味着它是预编译的,而“站点”意味着它不是。 I would opt for the former.我会选择前者。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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