tags:

views:

62

answers:

2

Where does this statement go? Do I put it in my constructor or do I call it in a method each time I make an asychronous request?

+1  A: 

You should call it exactly once, perhaps in a static constructor.

SLaks
+2  A: 

Here's an example for discussion.

WebRequest.RegisterPrefix("http://blog.wpfwonderland.com", 
       WebRequestCreator.ClientHttp);

Now that I've called the RegisterPrefix method all subsequent networking requests to that subdomain (blog.wpfwonderland.com) will use the client networking stack and not the browser stack.

You can call the RegisterPrefix anywhere in your code. There is no harm in calling this method more than once though according to the doc you can only do it once per domain. In fact your Silverlight application could have some network calls using the browser stack and others using the client stack. Let's say you want the HTTPS traffic to use browser stack and your HTTP traffic the client.

WebRequest.RegisterPrefix("http://":, WebRequestCreator.ClientHttp);
WebRequest.RegisterPrefix("https://", WebRequestCreator.BrowserHttp);

Each networking stack gives you different benefits. For example calling REST services are easier with ClientHttp. Here are some details at MSDN

http://msdn.microsoft.com/en-us/library/dd920295(v=VS.95).aspx

Walt Ritscher