How do I cast a webservice result to make it usable in a custom silverlight control?

I have designed a custom silverlight control that extends the standard datagrid.  This control provides a method to populate the grid which accepts an instance of a custom class I have created.  The control is housed in a number of different silverlight pages each of which call a web service to obtain an instance of the custom class and pass it off to the datagrid control to populate itself.

My problem is when the silverlight container page receives the object back from the webservice, the object's type is tied to the service reference for that silverlight application.  So, for example, if the "SilverlightContainer" page calls the webservice, the type of the object returned will be "SilverlightContainer.ServiceReference1.CustomDataObject".  This gets passed to the data grid, but because the data grid is in it's own class library, it is not part of the "SilverlightContainer.ServiceReference1" namespace.  It, therefore, does not know what to do with the object.

I have tried importing an identical service reference into the class library and casting as shown below, but receiving a casting exception.

ClassLibrary.ServiceReference1.CustomDataObject obj =  (ClassLibrary.ServiceReference1.CustomDataObject)ObjectPassedFromContainerPage;

Does anyone have any ideas on how to solve this?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Aaron JabamaniTechnical ArchitectCommented:
Instead of casting try to create a local object using the webservice object by assigning one by one else

Try to use XML to pass data from Web Service to your control. The WS should generate a xml with a schema understandable by your control.
pureautoAuthor Commented:
apeter, thanks for the response!  I've had to set that task aside for a couple days, but I will give your suggestion a shot when I get back to it.
pureautoAuthor Commented:
apeter, I apologize that it has taken me so long to get back to this question. Given your comment and some reading I've done, I am considering two options:

One: I could make the web service call from the page using the custom control and serialize the results, convert to XML, or something similar.  Then, pass that to the custom control to unpack.  The drawback I see here is an extra level of processing that may slow things down.  Also a possible limitation is keeping the object's definition synchronized between the custom control & the business layer.

Two: I could have the page using the custom control simply pass a SQL string from it's page.xaml.cs to the custom control, and allow the control to make the web service call to retrieve the object.  The problem here is that it appears the SQLCommand object is not available in Silverlight, so I would have to pass a plain text SQL string rather than a parameterized SQLCommand. Since my SQL query would sometimes include parameters from the page query string, this opens up the possibility of SQL injection.

What are your thoughts?
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

Aaron JabamaniTechnical ArchitectCommented:
Option looks good for me Since, you can reduce the out from webservice which is required for the control to unpack. Using LinqToXML you can easily unpack. Don't see any problem in processing.

Option 2 leads to security issues. Should avoid it.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Aaron JabamaniTechnical ArchitectCommented:
If you are worried about meassage size, you can also use JSON format to return the value from web service. JSON is lighter than XML result set.
pureautoAuthor Commented:
Thanks for your help!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.