?
Solved

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

Posted on 2011-09-06
4
Medium Priority
?
552 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

719 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