Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2011-09-06
4
Medium Priority
?
554 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 1000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

972 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