Solved

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

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

758 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

25 Experts available now in Live!

Get 1:1 Help Now