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?
pureautoAsked:
Who is Participating?
 
apeterConnect With a Mentor Commented:
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.
0
 
apeterCommented:
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.
0
 
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.
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
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?
0
 
apeterCommented:
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.
0
 
pureautoAuthor Commented:
Thanks for your help!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.