I suspect that is because you are using SOAP Serialization, not XML
Serialization.
Do you by chance have a SoapDocumentService or SoapRpcService attribute on
your code?
see
http://msdn.microsoft.com/library/en...iceclients.asp
The following demonstrates Xml Serialization. It generates the xml you want
( <MyClass>hello</MyClass> ).
To get this implicitly with webservices, you need to use decorate your
webmethod with
Use:=SoapBindingUse.Literal
using System.Xml.Serialization;
namespace Ionic {
public class MyClass
{
public MyClass() { }
public MyClass(string text)
{
this.Value = text;
}
[XmlText(typeof(string))]
public string Value;
}
/// XmlTextWriterFormattedNoDeclaration
/// helper class
public class XmlTextWriterFormattedNoDeclaration :
System.Xml.XmlTextWriter {
public XmlTextWriterFormattedNoDeclaration (System.IO.TextWriter w) :
base(w) { Formatting= System.Xml.Formatting.Indented;}
public override void WriteStartDocument () { }
}
public class TestDriver {
static void Main(string[] args) {
XmlSerializer s = new XmlSerializer(typeof(MyClass));
// use this to "suppress" the default xsd and xsd-instance namespace's
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add( "", "" );
MyClass c= new MyClass("hello");
// spit it out
System.Console.WriteLine("\nMyClass Serialized:");
s.Serialize(new
XmlTextWriterFormattedNoDeclaration(System.Console .Out), c, ns);
System.Console.WriteLine("\n");
}
}
}
"Lena" <ch********@hotmail.com> wrote in message
news:3a**************************@posting.google.c om...
I have generated a proxy class derived from
System.Web.Services.Protocols.SoapHttpClientProtoc ol
One of my classes is defined as
[System.Xml.Serialization.SoapTypeAttribute("MyClas s",
"http://www.mycompany.com")]
public class MyClass
{
public MyClass()
{
}
public MyClass(String text)
{
this.Value = text;
}
[XmlText(typeof(string))]
public string Value;
}
I wish for instances of this class to be serialized as
<tns:MyClass>hello world</tns:MyClass>
However it serializes as
<tns:MyClass><Value xsi:type="xsd:string">hello
world</Value></tns:MyClass>
I guess my use of XMLText() here doesn't work. Do anyone know how to
properly serialize element text?