Yes, I saw that in the documentation also. However I have tried many
different combinations all to no avail. The one I posted is simply one
"Martin Honnen" <mahotrash@yahoo.de> wrote in message
news:uRVrw7NbEHA.3512@TK2MSFTNGP12.phx.gbl...
>
>
> Bob Rundle wrote:
> > I can't seem to control the soap formatting. SoapTypeAttribute()
doesn't
> > seem to have any affect on the SOAP serialization. Here is my sampe
code.
> > What am I doing wrong?
>
>
>
> > MyClass a = new MyClass();
> > try
> > {
> > Stream sin = new FileStream(path,FileMode.Create);
> > SoapFormatter sfin = new SoapFormatter();
> > sfin.Serialize(sin,a);
>
>
> > [Serializable]
> > [SoapType("YourClass")]
> > class MyClass
> > {
> > public MyClass() { aprop=123; }
> > private int aprop;
> > public int Aprop
> > {
> > get { return aprop; }
> > set { aprop = value; }
> > }
> > }
> >
>
> I am not an expert on .NET serialization so don't take my answer as
> anything being authoritative but looking at the .NET documentation for
> SoapTypeAttribute it tells that the attribute is supposed to control the
> serialization with XmlSerializer while SoapFormatter is not mentioned
> there at all.
> An example using XmlSerializer and your class is
>
> using System;
> using System.Runtime.Serialization;
> using System.Runtime.Serialization.Formatters.Soap;
> using System.Xml;
> using System.Xml.Serialization;
> using System.IO;
>
> class Class1
> {
> /// <summary>
> /// The main entry point for the application.
> /// </summary>
> [STAThread]
> static void Main(string[] args)
> {
> string path = "test20040718SOAP.xml";
> MyClass a = new MyClass();
> try
> {
> XmlTypeMapping typeMapping = (new
> SoapReflectionImporter()).ImportTypeMapping(typeof(MyClass));
> Stream sin = new FileStream(path,FileMode.Create);
> XmlSerializer soapSerializer = new XmlSerializer(typeMapping);
> soapSerializer.Serialize(sin,a);
> sin.Close();
> }
> catch(Exception ex)
> {
> Console.WriteLine(ex);
> }
> }
> }
>
> [Serializable]
> [SoapType("YourClass")]
> public class MyClass
> {
> public MyClass() { aprop=123; }
> private int aprop;
> public int Aprop
> {
> get { return aprop; }
> set { aprop = value; }
> }
> }
>
> which results in the following XML
>
> <?xml version="1.0"?>
> <YourClass xmlns:xsd="
http://www.w3.org/2001/XMLSchema" > xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance" id="id1">
> <Aprop xsi:type="xsd:int">123</Aprop>
> </YourClass>
>
> which has the element name YourClass specified by the SoapType
> attribute. I realize that that is no SOAP message but that is all I can
> contribute, maybe someone else can tell you more about how/whether the
> SoapType attribute helps with the SoapFormatter.
>
> --
>
> Martin Honnen
>
http://JavaScript.FAQTs.com/ >