title: WebException NotFound received when using Silverlight with ASP.NET MVC
body: <p>I'm not entirely sure how to explain this, but basically I am trying to use a Silverlight application hosted within an ASP.NET MVC application. I have a basic controller on the MVC side that contains a method which accepts some string parameter and returns an ActionResult (for the purpose of this program, that result is some Json data).</p>
  
  <p>My problem arises when I handle the WebClient.OpenReadCompleted event within the Silverlight control. When the WebClient.OpenReadAsync method is called within this control, it successfully reaches the controller and then reports back to the relevant event handler as expected. However, when it is handled, the event arguments contain an error stating: "The remote server returned an error: NotFound.". </p>
  
  <p>Previously, I have noticed this is caused when some part of my communication URL is incorrect - in this case it is not. From some Googling, I have also noticed that this is a generic error. As such, I'm rather stumped. To make matters more confusing, I use this exact same communication attempt in another part of the program,  that retrieves an array of strings, and that works perfectly fine.</p>
  
  <p>Please see the example code below (due to the nature of this program, I am unable to post the full code).</p>
  
  <p><strong>Silverlight Control</strong></p>
  
  <pre><code>WebClient mClient = new WebClient();
  
  public void RequestData()
  {
      mClient.OpenReadAsync(new Uri("http://localhost:51234/Home/GetData"));
      mClient.OpenReadCompleted += new OpenReadCompletedEventHandler(mClient_OpenReadCompleted);
  }
  
  private void mClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
  {
      if(!e.Cancelled &amp;&amp; e.Error == null) // &lt;-- e.Error here is a WebException
      {
          var serializer = new DataContractJsonSerializer(typeof(Data));
          Data data = (Data)serializer.ReadObject(e.Result);
      }
  }
  </code></pre>
  
  <p><strong>MVC Controller - named HomeController and accessed with "Home"</strong></p>
  
  <pre><code>public ActionResult GetData()
  {
      return Json(new Data(), JsonRequestBehaviour.AllowGet);
  }
  </code></pre>
  
  <p><strong>Note</strong>
  Here, Data contains three members of types; string, string and byte array. For the purpose of serialization, I have exposed all three members through public properties containing both get and set parts. I have also added a public constructor taking no arguments.</p>
  
  <p>Any advice on this would be greatly appreciated.</p>
  
  <p>Many thanks in advance.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I've just tried the same bit of code with different data, and it works fine. I wondered if it was the size of the data (as the first attempt was with very large data), but I don't understand why that would matter if the call managed to hit the controller.</p>