473,561 Members | 3,076 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XML Deserialization

Is there a way to be notified when the deserialization of an XML is
complete, like a callback method?

I tried the IDeserializatio nCallback interface, but that doesnt for
XML-Deserialization .

thanks
josh

Dec 15 '05 #1
12 7751
Use a synchronous overload of the XmlSerializer.D eserialize method; when it
returns, it is finished.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.

"yoshijg" <jo*****@gmail. com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
Is there a way to be notified when the deserialization of an XML is
complete, like a callback method?

I tried the IDeserializatio nCallback interface, but that doesnt for
XML-Deserialization .

thanks
josh

Dec 15 '05 #2
Hi Kev,

Do you mean something like this...

--
FooType fooobj;
XmlSerializer xmlObj = new System.Xml.XmlS erialialzer(Typ eOf(FooType));
Filestream strObj = new Filestream("foo ", Open);
fooobj = xmlObj.Deserial ize( strObj );
fooObj.Deserial izeComplete(); //Notify manually
--

Yeah, i am doing that now... but I want the object being created inside
of the "Deserializ e" method to be notified when it's done being created
by the "XmlSerializer" .

I can do what you suggest and it's easy...but some coder may forget to
call "DeserializeCom plete". Now I can wrap this whole thing in a
function call, but that's just another hoop everybody doesnt need to
jump through.

Now why doesn't implementing IDeserializatio nCallback work?

Dec 15 '05 #3
I don't know why. How are you implementing it?

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.

"yoshijg" <jo*****@gmail. com> wrote in message
news:11******** **************@ g44g2000cwa.goo glegroups.com.. .
Hi Kev,

Do you mean something like this...

--
FooType fooobj;
XmlSerializer xmlObj = new System.Xml.XmlS erialialzer(Typ eOf(FooType));
Filestream strObj = new Filestream("foo ", Open);
fooobj = xmlObj.Deserial ize( strObj );
fooObj.Deserial izeComplete(); //Notify manually
--

Yeah, i am doing that now... but I want the object being created inside
of the "Deserializ e" method to be notified when it's done being created
by the "XmlSerializer" .

I can do what you suggest and it's easy...but some coder may forget to
call "DeserializeCom plete". Now I can wrap this whole thing in a
function call, but that's just another hoop everybody doesnt need to
jump through.

Now why doesn't implementing IDeserializatio nCallback work?

Dec 16 '05 #4
Hey kev,

Taking from the example above...

The only thing to add/note is that FooType implements the
IDeserializatio nCallback , and the call to deserialize looks like

FooType fooobj;
XmlSerializer xmlObj = new System.Xml.XmlS erialialzer(Typ eOf(FooType));
Filestream strObj = new Filestream("foo ", Open);
fooobj = xmlObj.Deserial ize( strObj );
---------------

Note, I am not calling OnDeserializati on manually like above.

Dec 16 '05 #5
What I meant was, how are you implementing IDeserializatio nCallback? The
code you just posted doesn't do this. Your question was "why doesn't it
work?" In order to see why it doesn't work, I have to see how you're using
it.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.

"yoshijg" <jo*****@gmail. com> wrote in message
news:11******** **************@ g49g2000cwa.goo glegroups.com.. .
Hey kev,

Taking from the example above...

The only thing to add/note is that FooType implements the
IDeserializatio nCallback , and the call to deserialize looks like

FooType fooobj;
XmlSerializer xmlObj = new System.Xml.XmlS erialialzer(Typ eOf(FooType));
Filestream strObj = new Filestream("foo ", Open);
fooobj = xmlObj.Deserial ize( strObj );
---------------

Note, I am not calling OnDeserializati on manually like above.

Dec 16 '05 #6
/*
Serializes/Deserializes properly as expected. But doesnt call the
OnDeserializati on();
*/

using System;
using System.Xml.Seri alization;
using System.IO;
using System.Runtime. Serialization;

namespace Test
{
public class Class1
{
[STAThread]
static void Main(string[] args)
{
//Serialize to disk first
Foobar fooObj = new Foobar();
XmlSerializer xml = new XmlSerializer(t ypeof(Foobar));
StreamWriter ios = new StreamWriter("f oobar.xml");
xml.Serialize(i os, fooObj);
ios.Close();

//Deserialize from disk
Foobar fooObj2 = null;
XmlSerializer xml2 = new XmlSerializer(t ypeof(Foobar));
FileStream ios2 = new FileStream("foo bar.xml",
FileMode.Open);
fooObj2 = (Foobar)xml.Des erialize(ios2);
ios2.Close();

}
}

[Serializable()]
public class Foobar
: IDeserializatio nCallback
{
private string m_Foo = "fooooo";

public string FooProperty
{
get
{
return m_Foo;
}
set
{
m_Foo = value;
}
}

public void OnDeserializati on(Object sender)
{
Console.WriteLi ne("Deserializa tion complete");
}
}
}

Dec 17 '05 #7
/*
Serializes/Deserializes properly as expected. But doesnt call the
OnDeserializati on();
*/

using System;
using System.Xml.Seri alization;
using System.IO;
using System.Runtime. Serialization;

namespace Test
{
public class Class1
{
[STAThread]
static void Main(string[] args)
{
//Serialize to disk first
Foobar fooObj = new Foobar();
XmlSerializer xml = new XmlSerializer(t ypeof(Foobar));
StreamWriter ios = new StreamWriter("f oobar.xml");
xml.Serialize(i os, fooObj);
ios.Close();

//Deserialize from disk
Foobar fooObj2 = null;
XmlSerializer xml2 = new XmlSerializer(t ypeof(Foobar));
FileStream ios2 = new FileStream("foo bar.xml",
FileMode.Open);
fooObj2 = (Foobar)xml.Des erialize(ios2);
ios2.Close();

}
}

[Serializable()]
public class Foobar
: IDeserializatio nCallback
{
private string m_Foo = "fooooo";

public string FooProperty
{
get
{
return m_Foo;
}
set
{
m_Foo = value;
}
}

public void OnDeserializati on(Object sender)
{
Console.WriteLi ne("Deserializa tion complete");
}
}
}

Dec 17 '05 #8
Well, you havent implemented the interface. See the following MSDN article:

http://msdn.microsoft.com/library/de...ationTopic.asp

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.

"yoshijg" <jo*****@gmail. com> wrote in message
news:11******** **************@ g49g2000cwa.goo glegroups.com.. .
/*
Serializes/Deserializes properly as expected. But doesnt call the
OnDeserializati on();
*/

using System;
using System.Xml.Seri alization;
using System.IO;
using System.Runtime. Serialization;

namespace Test
{
public class Class1
{
[STAThread]
static void Main(string[] args)
{
//Serialize to disk first
Foobar fooObj = new Foobar();
XmlSerializer xml = new XmlSerializer(t ypeof(Foobar));
StreamWriter ios = new StreamWriter("f oobar.xml");
xml.Serialize(i os, fooObj);
ios.Close();

//Deserialize from disk
Foobar fooObj2 = null;
XmlSerializer xml2 = new XmlSerializer(t ypeof(Foobar));
FileStream ios2 = new FileStream("foo bar.xml",
FileMode.Open);
fooObj2 = (Foobar)xml.Des erialize(ios2);
ios2.Close();

}
}

[Serializable()]
public class Foobar
: IDeserializatio nCallback
{
private string m_Foo = "fooooo";

public string FooProperty
{
get
{
return m_Foo;
}
set
{
m_Foo = value;
}
}

public void OnDeserializati on(Object sender)
{
Console.WriteLi ne("Deserializa tion complete");
}
}
}

Dec 17 '05 #9
Hey Kev,

Thanks for the article. I guess IDeserializatio nCallback only works
with the "BinaryFormatte r", which really seems counter intuitive.
Don't you? Wouldn't you expect a Callback to occur for any type of
Deserialization .
josh

Dec 18 '05 #10

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

Similar topics

2
2353
by: Serg | last post by:
Hi. I have a problem with deserialization decimal value. I have a simple class: public class A { public decimal d; } The serialization a value 0.00000001 is OK. The file is
3
1649
by: TEK | last post by:
There seems to be a bug when deserialization some classes in the .NET framework. If you try to deserialize a class that has a base class that holds a struct with a member that is implementing the ICollection interface, this causes the deserialization to fail. In my case this is a huge problem, and any suggestion for a workaround would be...
2
3821
by: Snowman | last post by:
Suppose I have a RootObject which holds a collection of other objects. The other objects have a property (Parent) which refers back to the "parent" collection (b.t.w. my collection is based on CollectionBase), in similar fashion as the object models of MS Office. I want to serialize this object graph (with RootObject as the xml document...
3
9786
by: Amadelle | last post by:
Hi all and thanks in advance for your help, I am having problems deserializing an object which seems to be serializing just fine. I save the byte array of the serialized object in the database (when I check the database the field that holds the binary data seems populated), but when I want to deserialize this same byte array the application...
3
2059
by: AnkitAsDeveloper [Ankit] | last post by:
Hi i am serializing a 'ref struct' object as follows : private: void Seri( String ^path, Object^ obj ) { FileStream^ fileStrm ; try { //Serialize entire object into Binary stream
3
9781
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 response. As a result of seraching news groups I guessed that the SOAP response defines an array element in a way that causes the dotnet...
1
3723
by: parrot toes | last post by:
I tried to post this question before, but there was an error when posting. I case it did get posted and in order to avoid duplication, I'll just repost a summary. I have written a dotnet client that accesses a Axis provided web service. The client uses the code generated, using wsdl.exe, from the wsdl file provided by the web service...
8
3452
by: ashoksrini | last post by:
Hi All, I have the below requirement and would like to get some feeback from the group on the best way to implement: 1. I have WSDL defined exposing few web services. 2. We dont have a requirement to have a server web service class. (reasons below) 3. I want to develop something like this - when client makes a web service call, on the...
5
2283
by: Greg Allen | last post by:
I am consuming a web service and using the generated Reference.cs to access the service and the objects associated with it. I have run into a problem where some inherited classes are not being deserialized. I have verified that the XML being returned by the service contains the tags I am expecting, but they don't show up in the resulting...
7
16133
by: Andrew | last post by:
Hi, I am using DataContractJsonSerializer to deserialize JSON string in C# objects but I am having a problem. Suppose I have a class: class Item { public ItemId Id { get; set; }
0
7644
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
1
7614
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6206
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5469
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5185
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3615
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3598
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2066
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1180
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.