serialising parameters manually

P

Pete Hearn

Can anyone tell me how to serialise an arraylist manually?

I have tried unsuccessfully to pass an arraylist to a webservice; then tried
an array of object[] which then whines about some xml serialisation issues -
I need to earn a living at some stage so think the fastest way round it
would be to serialise the objects to a string, pass the string as a
parameter (which does seem to work without all this hassle) - then
deserialise the string back into an object array inside the webservice.

Any help much appreciated!

Thanks
Peter

P.S. am I the only person who just wants this stuff to work? I'm a little
disappointed that I can't just pass an ArrayList across the wire to a
webservice without having to battle with .Net and XML first...
 
E

erymuzuan

well, why not use System.Collection.BaseCollection for your list, this
will generate a simple <element name="YourCollection" minOccurs="0"
maxOccurs="unbounded"/>

of course there's a way for you to properly serialize a .Net object even
a complex one, the deserialize it again at the other end using XML,
Base64String. in this example show you how to serialize .Net Exception.
bu t if you need this kind of capability , use remoting instead i.e.
when you don't care about interoperability.

[Serializable]
public class MySoapException
{

[XmlIgnore]
public Exception Exception;
public MySoapException()
{
//Required by XML serialization
}

public MySoapException(Exception Exception)
{
this.Exception = Exception;
}
public string ExeptionDetail{
get{
MemoryStream ms = new MemoryStream();
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(ms, this.Exception);
ms.Close();
return Convert.ToBase64String(ms.ToArray());
}
set{
MemoryStream ms = new MemoryStream(
Convert.FromBase64String(value));
BinaryFormatter bf = new BinaryFormatter();
this.Exception = (Exception)bf.Deserialize(ms);
ms.Close();
}
}
public MySoapException(string ExeptionDetail){
this.ExeptionDetail = ExeptionDetail;
}
}

Regards
Erymuzuan Mustapa
Regards
Erymuzuan Mustapa
 
P

Pete Hearn

Hi Chris - thank you for your response which I will definitely try out this
weekend. Want to reassure you that I do appreciate your time and the fact
that you are giving it for free - forgive me if I seemed to be demanding a
response like a spoiled kid throwing his toys out of the pram. It was borne
of frustration of being against a deadline and hitting a wall I couldn't
seem to scale.

At a higher level, the frustration was really that I just don't want to get
involved with all the plumbing of this stuff. To extend your analogy, is
the mechanic working on your brakes required to have an in-depth knowledge
of metallurgy, chemistry and physics so that he understands exactly how
brakes work? Of course not; chances are he's been shown how to change brake
pads and can do that very well. In the same way, I can drive my car very
well (23 years with no accidents at 25000 miles a year ain't bad!) and I
understand roughly how a petrol engine works to get good performance and not
break it. The whole power of the automobile is that millions of ORDINARY
people can use it without having to know much, if anything how it works.

There are quite a few programmers out there - me very definitely included -
who can't or don't want to grasp the details of XLM and all the little
tricks for getting data across a wire. We just need it to work to deliver a
solution FAST, and are totally happy to defer to MS or whoever to implement
the plumbing, just as we're happy for Ford's R&D team to get us to work each
day!

Thanks again Chris, and apologies if I upset you!

Best regards,
Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,828
Latest member
LauraCastr

Latest Threads

Top