获取 WCF 服务实现中参数的原始 XML

发布于 2024-12-20 14:01:35 字数 523 浏览 2 评论 0原文

我正在设置一个新的 .NET 4.0 WCF 服务,其方法(操作)采用强类型 XSD 生成的数据类型作为参数。这使得客户端的事情变得干净整洁——客户端可以使用强类型,而不必考虑 XML。

然而,在WCF服务的实现中,我更愿意将参数数据作为XML文档(LINQ XDocument)来处理,而不是反序列化的对象类型。 WCF 能够反序列化为显式类型,这很好,但对于我的通用算法来说,处理 xml 文档更方便、更灵活,主要是因为传入的数据是多态的。

我知道我可以只获取参数对象并将它们序列化回 XML,但这似乎很浪费。

我知道我可能可以用 XElement 替换强类型参数以获得我想要的实现便利性,但这将失去客户端的强类型(编译器检查、智能感知、自我文档)的好处。

有没有什么方法可以告诉 WCF,在我的服务实现中,我不需要反序列化参数对象,而是希望将它们作为 XML?

或者,是否有一种方法可以访问参数的原始 XML(在 WCF 将参数反序列化为对象之前)?如果我不能阻止 WCF 花费时间反序列化对象,至少这可以避免将它们重新序列化回 XML 的成本。

I'm setting up a new .NET 4.0 WCF service with a method (operation) that takes strongly typed XSD generated data types as parameters. This makes things clean and tidy for the client - the client can work with strong types and not have to think about XML.

However, in the implementation of the WCF service, I would prefer to deal with the parameter data as XML documents (LINQ XDocument) instead of the deserialized object types. It's nice that WCF will deserialize to explicit types, but for my generic algorithm it's more convenient and more flexible to deal with the xml documents instead, primarily because the incoming data is polymorphic.

I know I can just take the parameter objects and serialize them back down to XML, but this seems wasteful.

I understand that I could probably replace the strongly typed params with XElement to get what I want for implementation convenience, but this will lose the benefits of strong typing (compiler checks, intellisense, self documentation) for the client.

Is there any way to tell WCF that in my service implementation I don't need the parameter objects deserialized, that I want them as XML instead?

Or, is there a way to access the raw XML of the params as they were prior to WCF deserializing them into objects? If I can't prevent WCF from spending time deserializing the objects at least this would avoid the cost of reserializing them back to XML.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

辞慾 2024-12-27 14:01:35

一种方法是创建一个消息检查器来检查服务器上的传入消息,并对其进行操作(例如将其存储起来或其他东西)。

Pablo Pialorsi 有一篇很棒的博客文章关于如何编写消息检查器,分步

检查消息将使您能够访问原始 SOAP 消息格式的参数。

我认为参数检查器可能是更好的选择,但似乎这些检查器只有在这些参数已经被反序列化为对象后才可以处理任何服务调用的参数,因此这听起来不太可行方法....

One way to do this would be to create a message inspector that would inspect the incoming message on the server, and acting on it (e.g. storing it away or something).

Pablo Pialorsi has a great blog post on how to write a message inspector, step-by-step

Inspecting the message would give you access to the parameters in the raw SOAP message format.

I thought maybe a parameter inspector might be the better choice, but it would appear as though these inspectors only get their go at the parameters for any service call once those parameters have been deserialized into objects already, so that doesn't sound like a viable approach....

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文