views:

476

answers:

2

I am writing some code that needs to be backwards compatible with EXISTING remoting code that is using SOAP to serialize some objects.

My difficulty is that I have had to move some objects to new assemblies, so the remoting is broken.

For example, I serialize an object using the .NET SoapFormatter like this:

Person p=new Person();
string path=@"c:\myfile.soap";
using (System.IO.FileStream fs = new System.IO.FileStream(path, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write))
{
    System.Runtime.Serialization.Formatters.Soap.SoapFormatter
    f = new System.Runtime.Serialization.Formatters.Soap.SoapFormatter();
    f.Serialize(fs, p);
    fs.Close();
}

The resulting xml looks like this:

<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:clr="http://schemas.microsoft.com/soap/encoding/clr/1.0" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"&gt;
    <SOAP-ENV:Body>
     <a1:Person id="ref-1" xmlns:a1="http://schemas.microsoft.com/clr/nsassem/Serialization/dotneat_net.Serialization%2C%20Version%3D0.0.0.0%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3Dnull"&gt;
      <FirstName id="ref-3">Joe</FirstName>
      <LastName id="ref-4">Doe</LastName>
      <_Address id="ref-5">dotneat.net Street, Zaragoza, Spain</_Address>
      <_ZIPCode id="ref-6">50007</_ZIPCode>
     </a1:Person>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

In that XML, I'd like to have some control over the xmlns on the a1:Person object:

<a1:Person id="ref-1" xmlns:a1="http://schemas.microsoft.com/clr/nsassem/Serialization/dotneat_net.Serialization%2C%20Version%3D0.0.0.0%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3Dnull"&gt;

The reason is that my new Person object is not in the same assembly as the original object. So, later when deserialization occurs (in the older projects), it fails because of wrong assembly.

How can I control the text in the xmlns? I have tried a few things such as using the [SoapType Namespace="xxx"] attribute on the class that is being serialized. No luck.

I'd prefer to avoid modifying the XML manually.

A: 

Have you tried SoapAttribute? It has an XmlNamespace property. May be that will work. You can also use Reflector to see what SoapFormatter.Serialize is doing. You may get some ideas that you can try.

Mehmet Aras
+1  A: 
Tuzo
I will give this a try. I thought I tried this, but I may have done: [SoapType(NameSpace="MY_NAMESPACE"), instead of XmlNameSpace. Worth a shot, thanks.
jm
XmlNameSpace=... was the key. Thanks.
jm