How to get message from server after upload the file in silverlight 3?
I followed the example to upload files to the server successfully:
开发者_C百科http://www.c-sharpcorner.com/UploadFile/nipuntomar/FileUploadsilverlight03182009030537AM/FileUploadsilverlight.aspx
Is it possible to get a string message from the server on the webclient OpenWriteCompleted
event?
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!)
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.
精彩评论