Reputation: 59151
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.
Upvotes: 1
Views: 374
Reputation: 59151
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
and SoapServerProtocol
) is not directly exposed to the user.
You can use this code to at least get the guts of the request to map correctly:
XmlTypeMapping xmlTypeMapping = new SoapReflectionImporter()
.ImportTypeMapping(typeof(T));
var xmlSerializer = new XmlSerializer(xmlTypeMapping);
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):
Upvotes: 1