跨 WCF Web 服务请求序列化通用 XML 数据 [英] serializing generic XML data across WCF web service requests

查看:28
本文介绍了跨 WCF Web 服务请求序列化通用 XML 数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个向 WCF 服务发送请求的 Web 应用程序.WCF 服务获取一个 LINQ 结果集(anon.ilist)并将其作为回复发送回 Web 应用程序.为了让它快速工作,在 WCF 应用程序中,我使用 copytodatatable 并将其发送到我的数据集中的网络应用程序.

I've got a web app that sends a request to a WCF service. The WCF service gets a LINQ resultset (anon. ilist) and sends that in reply, back to the web app. In order to get it working quickly, inside the WCF app, i'm using copytodatatable and sending it to my web app in a DataSet.

然后,我的 Web 应用程序获取 DataSet 并将其写入 xml,执行一些 xslt 并将结果数据显示在屏幕上.完美的....嗯,不是真的.

My web app then takes the DataSet and writes it to xml, some xslt is performed and the resulting data is shown on screen. Perfect. ... Well, not really.

我还是(相对)WCF 新手.我知道发送 DataTables/DataSets 有点麻烦.Web 应用程序需要 xml 格式的数据(用于 xslt 操作),所以我想我会让 WCF Web 服务为我做 DataTable -> xml 工作,然后简单地用一个漂亮的 XmlDocument 回复客户端 webapp.
但是不能序列化 XmlDocument.

I'm still (relatively) new to WCF. I understand that sending DataTables/DataSets is a bit cumbersome. The web app wants the data in xml format (for the xslt operation), so I figured I'd get the WCF web service to do the DataTable -> xml work for me, and simply reply with a nice XmlDocument to the client webapp.
However a XmlDocument cannot be serialized.

通过 wcf 将 XML 数据发送到客户端的最佳方式是什么?

What's the best way of sending the XML data down to the client over wcf?

  • 数据表包含很多列,并且会经常更改,所以我不想创建自己的对象类(具有类似的 bazillion 属性)并发送它(因为这是我所做的以前在 wcf 中的大部分时间,它都运行良好......但不适合这种情况).

  • The datatable contains lots of columns, and will be changing quite freqently so i don't want to create my own object class (with like a bazillion properties) and send that (as this is what i've done most of the time previously in wcf, it works well... but isn't suited to this scenario).

编辑:将其作为字符串发送也可以....但这肯定不是最佳解决方案吗?

EDIT: Sending it down as a string works too.... but this surely can't be the best solution?

推荐答案

通过 WCF 发送数据集的唯一问题是它不可互操作 - 即您将无法使用来自非 .NET 的数据集客户.

The only problem with sending datasets over WCF is that it isn't interoperable - i.e. you wouldn't be able to use the dataset from a non-.NET client.

我曾在几个大型应用程序中工作,这些应用程序通过 WCF 通过网络发送数据集就很好.只要发送方和接收方都在 .NET 上运行,就应该没问题.

I've worked in several large applications that send Datasets across the wire via WCF just fine. As long as both the sender and receiver run on .NET you should be fine.

如果您仍然不想使用数据集,请考虑创建一个 DataContract 类来保存您的数据以通过网络发送.这是跨 WCF 传输数据的经典方式.除非您的 XML 非常复杂(很可能是这样),否则这可能是一个不错的选择.

If you still don't want to use datasets, then consider creating a DataContract class to hold your data to send across the wire. This is the classic way to transmit data across WCF. Unless your XML is pretty complex (which it may well be) this might be a good alternative.

如果您还没有,我强烈建议您阅读 Juval Lowy 出色的Programming WCF Services 2nd Edition"的副本.他有一整章是关于跨 WCF 传输信息的.这是 WCF 圣经.

If you don't already have it, I strongly suggest picking up a copy of Juval Lowy's excellent "Programming WCF Services 2nd Edition." He has a whole chapter on transmitting information across WCF. It's the WCF Bible.

这篇关于跨 WCF Web 服务请求序列化通用 XML 数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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