In Silverlight 2, by default, only able to talk back to the site of origin server is allowed.
To acheive that the HTTP request is going back to site of origin look at the deployment URI of the XAP and the request URI.
Comparing these two URIs, 3 things must match:
- Same domain. http://foo.com is different than http://bar.foo.com or http://www.foo.com
- Same protocol. http://foo.com is different than https://foo.com
- Same port. http://foo.com is different than http://foo.com:8080
HTTP requests themselves are:
- Asynchronous only
- Can only be initiated on the UI thread
There are two APIs in Silverlight for HTTP communication. The first is WebClient and the second is HttpWebRequest.
WebClient is a great API with a simple, events-based paradigm. Used to easily download a string or a Stream.
WebClient, behind the scenes, does a GET request and then gives back the result in the form required. It also automatically resolves relative URIs against the deployment URI of the XAP.
HttpWebRequest & HttpWebResponse
HttpWebRequest and HttpWebResponse are the standard .NET HTTP apis. They are much more powerful than WebClient but also more complex to use. Used to set headers or to issue a POST request.