WCF,向WCF服务发送未知类型 [英] WCF, Sending an unknown type to a WCF service

查看:76
本文介绍了WCF,向WCF服务发送未知类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑到这种情况,两个WCF客户端连接到一个WCF服务(服务器),该服务将从一个客户端接收一个对象,并通过一些操作协定和客户端回调将其发送给另一个WCF,这两个客户端都具有此类型对象,但我们不希望WCF服务(服务器)依赖于此类型.

Consider this scenario that two WCF clients connect to one WCF service(server), this service will receive an object from one client and send it to the other one through some operation contract and client callbacks, both clients have the type for this object but we do not want the WCF service(server) to be dependent on this type.

该项目远不止于此,但是我想知道您是否可以将类型未知的对象发送到服务,并以某种方式在另一个客户端上接收它.我看到了这一点,但对我没有任何帮助:

The project is much bigger than this, but I wonder if you can send an object with an unknown type to a service and somehow receive it back on the other client. I saw this but it does not help me at all: Can WCF service transmit type (client doesn't know this type) information?

谢谢.

推荐答案

在WCF中无法发送类型未知的对象",因为WCF需要与WSDL完全兼容-并且WSDL需要透明的类型定义.

Sending an "object" with unknown type is not possible in WCF because WCF requires a full compatibility with WSDL - and WSDL requires transparent type definition.

话虽如此,如果您使用object类型,我相信可以通过一种方式将其作为字符串加载,并且在WSDL中将其定义为xs:anyType.

Having said that, if you use a type of object I believe there is a way for this to be loaded as a string and in WSDL it is defined as xs:anyType.

我个人更喜欢将类型定义为字符串,并传递一个可以使用纯XML序列化进行序列化的XML.我在公司中使用过它,并且效果很好,特别是因为我们将XML作为文档存储在数据库中.

I personally would prefer defining the type as string and passing an XML which can be serialised using plain XML Serialization. I have used this in our company and it works really well, especially since we will be storing the XML as document in database.

这篇关于WCF,向WCF服务发送未知类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆