开发者

Difference between Project reference and Service reference in .NET

Whenever we are creating a .NET application we do consider several architecture like data access layer (DAL) or Business Layer (BL). In these layers normally we write code to interact with database. So to interact with these methods written in these layers we have several options. Here my focus is on Project reference and Service reference.

First one is - Right click on project << Add Reference << Select Project in Project tab Second one is – create asmx/wcf service host them in a project. Right click on project << Add Service Reference << Select desired service to interact.

What is the difference in both these options in terms of Performance or any other parameters 开发者_如何学C?


In terms of performance, the difference depends, but as a general rule, if both the service and the direct project reference perform the exact same computations on equally comparable systems, the project reference will result in less of a performance hit.

You're not really comparing apples to apples, here.

A reference to a project causes Visual Studio to compile the referenced project, and include the output (usually a .dll) with your main project. This means that there is a compiled (to bytecode anyway) bit of code that lives right with your application. referencing a project is similar to referencing a ,.dll or a com component directly in that you end up with a reference to a bit of code that lives within your application. Any processing that occurs is happening on the same machine as your code.

A reference to a service causes Visual Studio to generate a proxy client class that calls out to the service over the network (via HTTP, TCP, or other valid methods, depending on how the service is configured.) The service may live on your machine, or it may live on a server halfway around the globe. The processing done within the service is being done on that machine.

The reason I said early on that the performance is better with a project reference than a service reference if they perform the exact same computations is that the service does the computations AND has the overhead of establishing the network connection, dealing with network traffic, etc.

Of course other factors could affect performance. The service may be hosted on an old outdated machine with performance issues, in which case, the performance would be even worse on the service scenario.

On the other hand, if YOUR program is running on slow PC, but the SERVICE is running on a supercharged server, the fact that the processing is being done on a faster server may outweigh the performance hit of network traffic.

Incidentally, the use of services (what you get when you add a service reference) is a tenet of SOA (Service Oriented Architecture). The basic description, benefits, and uses are covered at Wikipedia: http://en.wikipedia.org/wiki/Service-oriented_architecture. That's as good a starting place as any. If you need to learn more, you can look into Web Services (SOAP and REST varieties - Visual Studio handles SOAP web services nicely) and then into WCF, which is a newer offering from Microsoft in the SOA world.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜