Reputation: 539
I followed the example to upload files to the server successfully:
Is it possible to get a string message from the server on the webclient OpenWriteCompleted
event?
Upvotes: 2
Views: 957
Reputation: 189505
Unfortunately this is one of a number of bizare design choices for the Silverlight WebClient, you can't access the Response easily having performed a POST. Its really odd since most POST operations have a useful response body.
However there are a number of things you can do. You could ditch the WebClient
and use WebRequest
/WebResponse
directly. You could inherit off the WebClient
and override GetWebResponse
so you can intercept it.
However a sneaky option if your string message is reasonably short is to add a custom HTTP header to the response.
The thread executing OpenWriteCompleted will block when the output stream is closed until a response is received. At that point you can access the ResponseHeaders
collection on the WebClient
object to retrieve the value of your custom header. (Why the Response stream hasn't been made available at the point escapes me!)
Upvotes: 5
Reputation: 57976
On your HttpHandler
you'll just need
context.Response.Write("You made it");
To read it on Silverlight side, you'll probably need to deal with OpenReadCompleted
event.
Upvotes: 0