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

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

问题描述

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



我的网络应用程序然后使用DataSet并将其写入xml,执行一些xslt,并将结果数据显示在屏幕上。完善。 ...好吧,不是真的。



我还是(相对较新)的WCF。我知道发送DataTables / DataSet是有点麻烦。 Web应用程序需要xml格式的数据(对于xslt操作),所以我想我会得到WCF Web服务为我做DataTable - > xml工作,并且只需回复一个不错的XmlDocument到客户端webapp。

但是XmlDocument不能被序列化。



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




  • datatable包含很多列,并且会有相当频繁的变化,所以我不想创建我自己的对象类(像一个bazillion属性)并发送(因为这是我以前在wcf中做的大部分时间,它工作得很好...但不适合这种情况)。


  • 编辑:以字符串的形式发送它....但这肯定不能是最好的解决方案?

    / li>

解决方案

通过WCF发送数据集的唯一问题是它不能互操作 - 即你不会能够使用非.NET客户端的数据集。



我已经在几个大型应用程序中工作,通过WCF通过WCF发送Datasets。只要发送方和接收方都运行在.NET上,您应该是可以的。



如果您仍然不想使用数据集,那么请考虑创建一个DataContract类保持您的数据通过电线发送。这是通过WCF传输数据的经典方式。除非你的XML非常复杂(可能是这样),这可能是一个很好的选择。



如果你还没有,我强烈建议拿起一个Juval Lowy的优秀编程WCF服务第2版的副本。他有一整章介绍跨国公司的信息传递。这是WCF圣经。


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.

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.

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.

What's the best way of sending the XML data down to the client over 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?

解决方案

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.

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.

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.

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天全站免登陆