title: C# Soap with Attachments | CustomEncoder mapping to CustomType
body: <p>i have a webservice, which is giving me some soap-with-attachments messages.
  since that's not supported in wcf, i wrote a custom encoder based on this one: <a href="https://archive.codeplex.com/?p=wcfswaencoder" rel="nofollow noreferrer">https://archive.codeplex.com/?p=wcfswaencoder</a></p>
  <p>it's receiving and the decoding the messages correctly, however the return types don't match.<br />
  I generated the service reference based on the wsdl as follows:</p>
  <p><a href="https://i.stack.imgur.com/KuXIz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KuXIz.png" alt="enter image description here" /></a></p>
  <p>The encoder doesn't know the type of course, i'm overwriting ReadMessage(...) to return a message object:<br />
  public override Message ReadMessage(System.IO.Stream stream, int maxSizeOfHeaders, string contentType)</p>
  <p>The returned Message has the attachment data as Message.Properties property, and the xml part as the message.</p>
  <p>after calling the webservice method, when debugging ReadMessage(), he's just jumping straight to the result, so somewhere in between the custom type must have been deserialized.</p>
  <p>The problem is the deserialization is not correct.
  The DataEntity + the name + the contentType are correct.
  But attachments are not correctly mapped to the DataEntity.Value.</p>
  <p>Is there a way to build the result object myself from the Message object?<br />
  Or how do i have to build the Message object so that it's correctly mapped to the custom result type?</p>
  <p>EDIT:
  As suggested by jdweng, i derived from IXmlSerializable and i get the message which i can now read however i want.
  Now the problem is, the message looks like this:<br />
  <a href="https://i.stack.imgur.com/qbfeF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qbfeF.png" alt="enter image description here" /></a></p>
  <p>i have no idea what to do with the [object Object].
  that should be the message, but how was that serialized?</p>