我有 WCF 服务,它可以接受并返回 List> 形式的相当大量的数据。我的问题是典型行的输出如下所示:
<d:ArrayOfanyType>
<d:anyType i:type="e:string" xmlns:e="http://www.w3.org/2001/XMLSchema">PJ123</d:anyType>
<d:anyType i:type="e:double" xmlns:e="http://www.w3.org/2001/XMLSchema">2</d:anyType>
<d:anyType i:type="e:string" xmlns:e="http://www.w3.org/2001/XMLSchema">216565</d:anyType>
<d:anyType i:type="e:dateTime" xmlns:e="http://www.w3.org/2001/XMLSchema">1993-09-10T00:00:00</d:anyType>
<d:anyType i:type="e:string" xmlns:e="http://www.w3.org/2001/XMLSchema">Timesheet W/E 11/9/93 Franklin</d:anyType>
<d:anyType i:type="e:string" xmlns:e="http://www.w3.org/2001/XMLSchema">CONSULT OF</d:anyType>
<d:anyType i:type="e:double" xmlns:e="http://www.w3.org/2001/XMLSchema">25</d:anyType>
<d:anyType i:type="e:double" xmlns:e="http://www.w3.org/2001/XMLSchema">0</d:anyType>
<d:anyType i:type="e:double" xmlns:e="http://www.w3.org/2001/XMLSchema">25</d:anyType>
</d:ArrayOfanyType>
因此,每行中的每个值都定义了“e”命名空间,这大大增加了消息的大小。我知道这背后的原因是 DataContractSerializer 不必进行 2 次传递,但以更大的消息大小为代价来获得一点处理性能似乎很有限。我考虑过如何更改数据结构,但字段实际上可以是任何东西,我无法避免使用
元素。
有谁知道拦截 WCF 管道并删除/重新组织这些名称空间声明的方法吗?
I have WCF service that can accept and return fairly large amounts of data in the form of a List<List<object>>. My problem is that the output of a typical row looks like this:
<d:ArrayOfanyType>
<d:anyType i:type="e:string" xmlns:e="http://www.w3.org/2001/XMLSchema">PJ123</d:anyType>
<d:anyType i:type="e:double" xmlns:e="http://www.w3.org/2001/XMLSchema">2</d:anyType>
<d:anyType i:type="e:string" xmlns:e="http://www.w3.org/2001/XMLSchema">216565</d:anyType>
<d:anyType i:type="e:dateTime" xmlns:e="http://www.w3.org/2001/XMLSchema">1993-09-10T00:00:00</d:anyType>
<d:anyType i:type="e:string" xmlns:e="http://www.w3.org/2001/XMLSchema">Timesheet W/E 11/9/93 Franklin</d:anyType>
<d:anyType i:type="e:string" xmlns:e="http://www.w3.org/2001/XMLSchema">CONSULT OF</d:anyType>
<d:anyType i:type="e:double" xmlns:e="http://www.w3.org/2001/XMLSchema">25</d:anyType>
<d:anyType i:type="e:double" xmlns:e="http://www.w3.org/2001/XMLSchema">0</d:anyType>
<d:anyType i:type="e:double" xmlns:e="http://www.w3.org/2001/XMLSchema">25</d:anyType>
</d:ArrayOfanyType>
So every value in each row has the "e" namespace defined which greatly increases the size of the message. I know the reasoning behind this is so that the DataContractSerializer doesn't have to make 2 passes but it seems potty to gain a little processing performance at the expense of MUCH bigger message sizes. I've thought about how I could change the data structure but the fields really could be anything to I can't avoid the use of <anyType>
elements.
Does anyone know of a way of intercepting the WCF pipeline and removing/reorganising these namespace declarations?
发布评论
评论(1)
您可以使用自定义编码器来做到这一点 - 此时您可以随心所欲地使用 XML。正如约翰·桑德斯(John Saunders)指出的那样,这将导致(可能是重大的)性能下降,但它确实有效。下面的代码显示了您将如何处理它。
You can use a custom encoder to do that - at that point you can play with the XML as much as you want. As John Saunders pointed out, this will incur a (possibly significant) performance hit, but it certainly works. The code below shows how you'd do about it.