Remoting or WCF for new development (between two .NET apps on the same machine) using interfaces?

自作多情 提交于 2019-11-30 08:51:37

Remoting has some use cases, such as communication among appdomains within a single process. Having said that, yes, WCF is the way to go. From some of the things you've said, though, I'm not sure if you understand how this is supposed to work.

The usual way to do things in WCF is to create a shared assembly consisting entirely of data transfer objects (all properties, no code) and interfaces. Both sides reference this assembly, but the client uses a service reference of the server. Does that help?

WCF is the way to go, specifically check out the Net Named Pipe binding with WCF. This will allow very fast interprocess communication on the same machine.

If your targeting Windows Server 2008 for your production deployment then you can leverage IIS 7 as a hosting environment. Check out Extend Your WCF Services Beyond HTTP With WAS.

There is lots of WCF getting started type information out there. Check out:

If your having problems getting started, then post any specific errors, or examples, you might have demonstrating it and I'm sure someone here can help!

Used both.

Definitely go with WCF.

Remoting is badly documented and touchy. WCF is so much easier by comparison. Not sure the issues you're having but there's tons of docs on WCF out there.

I just switched a program over from remoting to WCF and I have come across a bunch of things that used to work seamlessly in remoting but that causes problems in wcf:

  • The CallContext class is gone. I used that for passing some information about e.g. the currently selected language and some info about the user. With WCF I had to create a MessageInspector to add headers with this info to every request.
  • The exceptions are no longer passed through unchanged. Instead you need to use the FaultException and FaultContracts.
  • The proxies don't seem to be as light weight. I need to dispose them instead of just leaving them to be garbage collected or else my service will hang. (Actually it isn't even as simple as calling Dispose to correctly terminate a proxy you need a fairly complex sequence of try, catch, finally that calls Close and Abort for different types of exceptions.) The need to close the proxies causes a bit of a problem where I want my IoC framework to manage the proxies.

I am not saying you should use Remoting, I'm just saying that there are reasons to consider Remoting as well. It is definitely the simpler one to set up and get to work.

I guess you could argue that I ran into some of these problems only because I wasn't using best practices in my Remoting program, though. :-P

Here one pattern to do Remoting-like things with WCF:

  • 3 projects: server, client, shared.dll
  • server and client both reference shared.dll
  • put the service interface with [ServiceContract] into shared.dll
  • put service implementation class into the server
  • don't use interfaces for your data types
  • create bare-bones DataContract types with only the logic you want shared between client and server (e.g. validation)
  • put your DataContract data types into shared.dll
  • Don't use NetDataContractSerializer (like you seem to be doing in your code)

There are variations on this theme of course. E.g. instead of the shared dll you can share code files between server and client projects with #if for different compilation.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!