我有一个网络服务代理。在该代理上有一个采用两种自定义类型的方法。当我调用 Web 服务时,会生成一条肥皂消息。
在我的场景中,我手动捕获肥皂消息(使用提琴手)。我希望能够将包含此肥皂消息(我从手动创建的文件中读取)的字符串反序列化回我的两种原始类型的实例。
我知道使用这两种类型的 Xml DOM、XPath 和 Xml 序列化很容易做到这一点。我已经在这样做了,尽管目前有两个单独的文件。我想将它们组合起来,并希望避免手动格式化捕获的 Soap 消息。
是否有更自动的方法来利用现有的 Soap 基础设施来进行反序列化?我想编写一次序列化代码,并希望它能够工作。
I have a web service proxy. On that proxy there is a method that takes two custom types. When I call the web service, a soap message is generated.
In my scenario, I capture that soap message manually (using fiddler). I would like to be able to de-serialize a string containing this soap message (that I read from a manually created file) back into instances of my two original types.
I know this is easy enough to do with Xml DOM, XPath, and Xml serialization for those two types. I'm already doing this, though currently with two separate files. I'd like to combine them, and like to avoid manual formatting of the captured Soap message.
Is there a more automatic way to leverage the existing Soap infrastructure to do this deserialization? I'd like to write that serialization code once and simply expect it to work.
发布评论
评论(1)
看来 .Net 框架并没有以易于使用的方式公开这一点。写入/读取数据的自定义代码(在
SoapHttpClientProtocol
和SoapServerProtocol
中)不会直接向用户公开。您可以使用此代码至少让请求的内容正确映射:
您必须自己完成其余的序列化/反序列化(通过使用自定义代码编写 SOAP 标头和正文,并跳过 XML 阅读器来完成分别是您的内容)。
您也可以尝试使用
SoapFormatter
,尽管它已被弃用,并且对于很多场景(包括泛型)来说都非常糟糕:It appears the .Net framework doesn't expose this in an easy to use manner. The custom code that writes/reads the data (in
SoapHttpClientProtocol
andSoapServerProtocol
) is not directly exposed to the user.You can use this code to at least get the guts of the request to map correctly:
The rest of the serialization/deserialization you will have to do yourself (via writing the SOAP header and body with custom code, and skipping your XML reader ahead to your content, respectively).
You could also try using
SoapFormatter
, though it is deprecated, and quite broken for a lot of scenarios (including generics):