简体   繁体   English

为什么.Net Remoting不需要已知类型但WCF需要呢?

[英]Why .Net Remoting doesn't need known types but WCF does?

We are migrating our .net Remoting app to use WCF. 我们正在迁移.net Remoting应用程序以使用WCF。 One thing that confuses me now is the concept of "Known types" that WCF introduced but not needed by Remoting. 现在让我感到困惑的一件事是WCF引入但Remoting不需要的“已知类型”的概念。 While I am sort of understand what the known types are and what they do, what I am confused about is the difference between WCF and Remoting - On the sender's side, if WCF doesn't have enough type information about the object at hand to serialize it, why does Remoting? 虽然我有点理解已知类型是什么以及它们做了​​什么,但我感到困惑的是WCF和Remoting之间的区别 - 在发送方方面,如果WCF没有足够的关于手头对象的类型信息来序列化,为什么要远程处理? Same for the receiver: Why .net Remoting doesn't have a problem deserializing an object received but WCF does? 对于接收者来说也是如此:为什么.net远程处理没有问题反序列化收到的对象但是WCF呢? Is that because Remoting sends metadata along with the data? 那是因为Remoting会发送元数据和数据吗? If so why can't WCF do the same? 如果是这样,为什么WCF不能这样做呢?

You're correct - .NET remoting sends type metadata with the requests. 您是正确的-.NET远程发送带有请求的类型元数据。 WCF can do the same, but by default it doesn't - it's a lot of extra information which makes the requests larger and more complex to process (affecting performance). WCF 可以做同样的事情,但默认情况下不会这样做 - 这是一些额外的信息,使得请求更大,处理更复杂(影响性能)。 Not sending the type information also allows for loosely coupled systems, where the client and the server can version separately, and as long as they adhere to the contracts established in the original version, they will continue working. 不发送类型信息还允许松散耦合的系统,其中客户端和服务器可以分别进行版本控制,只要它们遵守原始版本中建立的合同 ,它们就可以继续工作。 And it also allows for WCF to talk to systems written in non-NET platforms (which isn't possible with remoting or other technologies which rely on shared type information). 它还允许WCF与非.NET平台上编写的系统进行通信(这对远程处理或依赖共享类型信息的其他技术是不可能的)。

If you really want to go with the non-known-types way, you can replace the default serializer used by WCF (the DataContractSerializer ) with the NetDataContractSerializer , which will send type information with each request. 如果您真的想使用非已知类型的方式,可以使用NetDataContractSerializer替换WCF( DataContractSerializer )使用的默认序列化程序, NetDataContractSerializer将为每个请求发送类型信息。 To use that, search for "wcf netdatacontractserializer" and you'll find how to use it. 要使用它,搜索“wcf netdatacontractserializer”,您将找到如何使用它。

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

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