Solved

How to send a deserialized object from a Silverlight client to a server through WCF

Posted on 2011-09-06
4
548 Views
Last Modified: 2012-05-12
Once I serialize an object on a Silverlight client, how do I send it to the server?

To more clearly state my purpose, I want to serialize an object on my Silverlight client, call a method on the server's .svc file, deserialize the object on the server, store it in a session, and then retrieve it later.

But when I create the method on the .svc file, I don't know what type of object to pass in the parameter if I am passing in a serialized object.

In other words, if I am passing in an int I could have:
public void someMethod(int x){...}

If I am passing in a string I could have:
public void someMethod(string x){...}

What type to I pass in if I have a serialized object?

I have Silverlight 4 and visual studio 2010.
0
Comment
Question by:XTO
  • 2
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
zvytas earned 250 total points
ID: 36488613
You can use strings to send serialized objects:

// CLIENT SIDE

// serialise object to a string
object objectToSerialize = ...;
StringWriter sw = new StringWriter();
XmlSerializer s = new XmlSerializer( typeof( ShoppingList ) );
s.Serialize( sw, objectToSerialize );
string serializedXml = sw.ToString();
// call a method and pass serializedXml



// SERVER SIDE

// deserialise string to an object
XmlSerializer s = new XmlSerializer( typeof( ShoppingList ) );
object = (object)s.Deserialize( new StringReader( serializedXml ) );
0
 

Author Comment

by:XTO
ID: 36488803
Excellent. Thank you zvytas.
Do you know if that works with DataContractSerializer as well as XmlSerializer?
0
 
LVL 5

Expert Comment

by:zvytas
ID: 36489140
Yes, the serializer you use doesn't really matter as long as you use the same thing on both ends (client and server).
0
 

Author Closing Comment

by:XTO
ID: 36489207
I appreciate how quickly the question was answered.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question