Solved

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

Posted on 2011-09-06
4
543 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

937 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now