473,387 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

serializing element text using SOAP

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?
Nov 12 '05 #1
1 1774
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?

Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Scott Meddows | last post by:
I'm trying to serialize an object in VB.NET. I have all my objects denoted with the <Seralizable()> Attribute. This is the code I am using... Dim sf As SoapFormatter = New SoapFormatter Dim...
1
by: cjmumford | last post by:
I have a couple of C# objects like this: class Foo { } class Bar { Foo m_foo; Foo foo {
2
by: Tobias Zimmergren | last post by:
Hi, just wondering what serializing really is, and howto use it? Thanks. Tobias __________________________________________________________________ Tobias ICQ#: 55986339 Current ICQ status: +...
0
by: JackRazz | last post by:
I'm trying to serialize a collection to a file stream by serializing each object individually. The code below works fine with the BinaryFormatter, but the SoapFormatter reads the first object and...
0
by: Matt S | last post by:
Hello, I'm trying to build a C# client to consume an AXIS Web Service (running SOAP over HTTP). The Web Service encodes full server-side exception traces in the Soap Fault > Detail element...
3
by: GT | last post by:
I have a .NET client that consumes an Axis web service. A change was made recently to the AXIS web service, and ever since then my .NET proxy class has been throwing an InvalidCastException. The...
3
by: jparulan | last post by:
Hi All, I'm using SOAP3.0. I was able to successfully call a WSDL file and get a value properly. But when the WSDL changed to have a MULTIPLE <element name> it was failing. This code works...
2
by: forcey | last post by:
Hi all, I'm writing a SOAP server using the SOAP extension and I need to return an array_map_name_balance, which is defined in a WSDL file like this: <xsd:complexType name="map_name_balance">...
0
by: nappingcub | last post by:
This is my first time coding a web service in .NET and ran into a slight snag that I was hoping that anyone could help me out on. I'm using the generic Hello World web service that is stubbed out on...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.