473,385 Members | 1,486 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,385 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 1773
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.