Silverlight Client issues

552 views
Skip to first unread message

John

unread,
May 6, 2011, 11:48:12 AM5/6/11
to ServiceStack .NET Open Source REST Web Services Framework
I've been using your redis client for a couple months now and love it.
But now I want to access that server with web services via JSON and
figured why not try the solution from ServiceStack.

I have setup an ASP.NET project and used NuGet to install
ServiceStack. I'm using the /hello/{Name*} example and I just want to
get that response into a silverlight application. I'm just having no
luck at all.

In my project for the web service, I've put the crossdomain.xml file
at the root, but i'm still getting this error.

{System.Reflection.TargetInvocationException: An exception occurred
during the operation, making the result invalid. Check InnerException
for exception details. ---> System.Security.SecurityException --->
System.Security.SecurityException: [Arg_SecurityException]
Arguments:

Debugging resource strings are unavailable. Often the key and
arguments provide sufficient information to diagnose the problem. See
http://go.microsoft.com/fwlink/?linkid=106663&Version=5.0.60401.00&File=mscorlib.dll&Key=Arg_SecurityException

Is there anything else I need to do server or client side to pull the
JSON object back with out errors?

Thanks,
John

Demis Bellot

unread,
May 6, 2011, 11:55:46 AM5/6/11
to servic...@googlegroups.com
Hi John,

For connectivity problems like this, it's best to start with the basics so we can best identify where the problem is.

The first thing I would do is see if you can download the remote web service content as a string? using either the built-in HttpWebRequest or WebClient in Silverlight.

You want to make sure you can get this working first, I also recommend having something like Fiddler or WireShark on hand so you can actually see Silverlight making the request.

Cheers,

John

unread,
May 6, 2011, 12:07:18 PM5/6/11
to ServiceStack .NET Open Source REST Web Services Framework
Hi Demis,

Thanks for the quick reply.

I'm currently just trying to use the webclient. This is my code.

1 WebClient wc = new WebClient();
2 string url = @"http://localhost/ServiceStackHello/json/
syncreply/hello/ted";
3
4 Uri queryUri = new Uri(url);
5 wc.OpenReadCompleted += new
OpenReadCompletedEventHandler(wc_OpenReadCompleted);
6 wc.OpenReadAsync(queryUri);
7
8 void wc_OpenReadCompleted(object sender,
OpenReadCompletedEventArgs e)
9 {
10 JsonObject completeResult =
(JsonObject)JsonObject.Load(e.Result);
11 JsonArray resultsArray =
(JsonArray)completeResult["Result"];
12 }

Inside OpenReadCompleted I always get an execption with e.Result.
> >http://go.microsoft.com/fwlink/?linkid=106663&Version=5.0.60401.00&Fi...

Demis Bellot

unread,
May 6, 2011, 12:17:00 PM5/6/11
to servic...@googlegroups.com
I'm still not sure if you're able to make a successful connection or not (i.e. if its an XSS issue).

Can you download a simple text file from the ASP.NET website that hosts ServiceStack? e.g. http://localhost/ServiceStackHello/test.txt

If that works can you provide a fiddler or wireshark output? basically we need to find out if the request actually gets made and the response is returned, otherwise we need to find out why by looking at the previous requests, i.e. whether there is any 500 or 404s e.g to crossdomain.xml

- Demis

John

unread,
May 6, 2011, 1:28:45 PM5/6/11
to ServiceStack .NET Open Source REST Web Services Framework
It seems I do have a crossdomain issue. I can't download a simple
file. I'll keep working on that and let you know my success.

On May 6, 11:17 am, Demis Bellot <demis.bel...@gmail.com> wrote:
> I'm still not sure if you're able to make a successful connection or not
> (i.e. if its an XSS issue).
>
> Can you download a simple text file from the ASP.NET website that hosts
> ServiceStack? e.g.http://localhost/ServiceStackHello/test.txt

John

unread,
May 6, 2011, 3:13:04 PM5/6/11
to ServiceStack .NET Open Source REST Web Services Framework
I've narrowed it down to IIS, If i run using iis express it works
fine.

So now that I can get it working and if I do something like

JsonObject completeResult = (JsonObject)JsonObject.Load(e.Result);
foreach (var c in completeResult)
{
MessageBox.Show(c.Value.ToString());
}

It works but the Value is a string.

How do I connect to the web service and get a direct C# object back?

Demis Bellot

unread,
May 6, 2011, 3:43:06 PM5/6/11
to servic...@googlegroups.com
Hi John,

Well if you have the JSON string then converting it back into your DTO depends on the Json Serializer used.

Stack Overflow has some suggestions with various JSON serializers here:

I'm not familiar with how you would do it with JsonObject? but I'm guessing it has to be supported somehow as it's a common task that everyone would want to do.

Ideally we could just use the ServiceStack serializers in ServiceStack.Text to do the de/serialization but because of some uses of Reflection.Emit it requires some source changes for it to work (which is still on my TODO list). 

However I've also maintained a dependency-free version of ServiceStack.Clients that uses the BCL's DataContractJsonSerializer (i.e. not the superfast ServiceStack.Text ones :) that you could use in the meantime:
It is effectively just a port of the main C# ServiceStack clients which lives here: 

I've published 4.0 Client profile builds of the above ServiceStack.Client here:
Reply all
Reply to author
Forward
0 new messages