473,320 Members | 1,957 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,320 software developers and data experts.

SOAP XMLTypeMapping Deserialization

I'm trying to serialize/deserialize an object in SOAP-encoded form.
I'm using the code below. Serialization succeeds fine, but when I try
to deserialize I get an exception. Can anyone tell me how I can
deserialize an object which has been serialized this way? Do I need
to do something special with an XmlReader?

(I don't have access to the underlying objects, so SoapFormatter is
not an option for me.)

Thanks,
Ben

public void save(object obj, String filepath) {
XmlTypeMapping xmlType =
(new SoapReflectionImporter()).ImportTypeMapping(obj.Ge tType());
StreamWriter writer = null;
XmlTextWriter xw = null;
try {
writer = new StreamWriter(new FileStream(filepath,
FileMode.Create,
FileAccess.Write,
FileShare.None));
xw = new XmlTextWriter(writer);
XmlSerializer ser = new XmlSerializer(xmlType);
xw.WriteStartDocument();
xw.WriteStartElement("root");
ser.Serialize(xw, obj);
xw.WriteEndElement();
} finally {
if (xw != null) {
xw.Close();
}
if (writer != null) {
writer.Close();
}
}
}

public object load(String filepath, Type type) {
XmlTypeMapping xmlType =
(new SoapReflectionImporter()).ImportTypeMapping(type);
StreamReader reader = null;
try {
XmlSerializer xmlSerializer = new XmlSerializer(xmlType);
reader = new StreamReader(new FileStream(filepath,
FileMode.Open,
FileAccess.Read,
FileShare.Read));
object o = xmlSerializer.Deserialize(reader);
return o;
} finally {
if (reader != null) {
reader.Close();
}
}
}
Nov 11 '05 #1
3 6001
What kind of exception do you get when deserializing?

~Martin Chamberlain

--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm.
"Ben Engber" <be*******@yahoo.com> wrote in message
news:d6**************************@posting.google.c om...
I'm trying to serialize/deserialize an object in SOAP-encoded form.
I'm using the code below. Serialization succeeds fine, but when I try
to deserialize I get an exception. Can anyone tell me how I can
deserialize an object which has been serialized this way? Do I need
to do something special with an XmlReader?

(I don't have access to the underlying objects, so SoapFormatter is
not an option for me.)

Thanks,
Ben

public void save(object obj, String filepath) {
XmlTypeMapping xmlType =
(new SoapReflectionImporter()).ImportTypeMapping(obj.Ge tType());
StreamWriter writer = null;
XmlTextWriter xw = null;
try {
writer = new StreamWriter(new FileStream(filepath,
FileMode.Create,
FileAccess.Write,
FileShare.None));
xw = new XmlTextWriter(writer);
XmlSerializer ser = new XmlSerializer(xmlType);
xw.WriteStartDocument();
xw.WriteStartElement("root");
ser.Serialize(xw, obj);
xw.WriteEndElement();
} finally {
if (xw != null) {
xw.Close();
}
if (writer != null) {
writer.Close();
}
}
}

public object load(String filepath, Type type) {
XmlTypeMapping xmlType =
(new SoapReflectionImporter()).ImportTypeMapping(type);
StreamReader reader = null;
try {
XmlSerializer xmlSerializer = new XmlSerializer(xmlType);
reader = new StreamReader(new FileStream(filepath,
FileMode.Open,
FileAccess.Read,
FileShare.Read));
object o = xmlSerializer.Deserialize(reader);
return o;
} finally {
if (reader != null) {
reader.Close();
}
}
}

Nov 11 '05 #2
Ben,

the code below works for me. Is this similar to what you are using:

public static object load(String filepath, Type type)
{
XmlTypeMapping xmlType =
(new SoapReflectionImporter()).ImportTypeMapping(type);
XmlTextReader reader = null;
object o = null;
try
{
XmlSerializer xmlSerializer = new XmlSerializer(xmlType);
reader = new XmlTextReader( filepath );
bool keepGoing = true;
while( keepGoing )
{
// fast forward to the root element
keepGoing = reader.Read() && ( "root" != reader.Name );
}
reader.Read(); // get past the root element
o = xmlSerializer.Deserialize(reader);
}
catch( Exception ex )
{
Console.WriteLine( ex.Message );
}
finally
{
if (reader != null)
{
reader.Close();
}
}
return o;
}

--
HTH
Christoph Schittko [MVP]
Software Architect, .NET Mentor

"Ben Engber" <be*******@yahoo.com> wrote in message
news:d6**************************@posting.google.c om...
A good question. Save() works fine. Here is the exception I get when
I invoke Load():

System.InvalidOperationException: There is an error in XML document
(2, 2). ---> System.InvalidOperationException: <root xmlns=''> was not
expected.

at Microsoft.Xml.Serialization.GeneratedAssembly.XmlS erializationReader1.Read6_
AssetSet()
--- End of inner exception stack trace ---

at System.Xml.Serialization.XmlSerializer.Deserialize (XmlReader
xmlReader, String encodingStyle)

at System.Xml.Serialization.XmlSerializer.Deserialize (TextReader
textReader)

at NFAQ.DAL.FileDataAccess.load(String filepath, Type type) in
c:\build\nfaaddin-noinstaller\nfaq.dal\filedataaccess.cs:line 67

I figure I need to use an XmlTextReader to consume the outermost
element much like how I write it with the XmlTextWriter. But
everything I try fails with similar exceptions. How exactly do I need
to process the input (or output) so that I can deserialize it?

Thanks,
Ben


"SQL Server Development Team [MSFT]" <sq****@microsoft.com> wrote in

message news:<e1**************@TK2MSFTNGP10.phx.gbl>...
What kind of exception do you get when deserializing?

~Martin Chamberlain

Nov 11 '05 #3
Your code works like a charm. The problem was that I was misusing XmlTextReader.

Thank you for the help!

-Ben
Nov 11 '05 #4

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

Similar topics

2
by: Bob Rundle | last post by:
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? Regards, Bob Rundle ...
3
by: parrot toes | last post by:
Summary: I have been trying to make requests of a web service provided by Axis using a dotnet client with code generated by wsdl.exe and have been getting exceptions when trying to process the...
3
by: Jon Paugh | last post by:
Hi, If I have two soap extensions, one to encrypt data, and the other to compress data, which should have higher priority on the client, and on the server? The information I have indicates...
3
by: JRey | last post by:
Does .Net generate the classes for Faults when they are specified in the WSDL. I tried defining them and then generating a proxy, and it did not appear to do it. On the Java side it did generate...
4
by: Jon Davis | last post by:
When people discuss XML Web Services in the context of .NET, and they talk about their WSDL file and the like, does this infer SOAP? Or are there other XML-based web protocols besides SOAP that...
6
by: Vinit | last post by:
Hi I am passing an arraylist to a c#/.net webmethod from a perl client using soap:lite. The trace shows the elements in the xml request. The arraylist input in the webmethod however does not...
6
by: J. Dudgeon | last post by:
Is it possible to configure a .NET 2.0 ASMX Web service to accept namespace qualified messages? For instance, instead of: <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"...
1
by: Gregor D. | last post by:
Hi, I want to consume an Apache Webservice with a C# .NET Client. Everything works fine, but I'm having problem with the deserialization of the complex type "Item" that is included in the...
2
by: =?Utf-8?B?RmFicmljaW8gRmVycmVpcmE=?= | last post by:
Hi, I'm facing an odd problem when consuming some web services in .Net. After call a web method, the response SOAP envelope isn't being deserialized properly. In fact, all href tags are not...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work

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.