Silverlight 4,谷歌浏览器和HttpWebRequest问题

时间:2010-06-14 09:45:26

标签: asp.net-mvc-2 google-chrome httpwebrequest silverlight-4.0

在ASP.NET MVC 2中托管的我的Silvrlight 4应用程序在通过Internet Explorer 8使用时工作正常,无论是在开发服务器还是远程Web服务器(IIS 6.0)中。但是,当我尝试浏览Google Chrome(版本5.0.375.70)时,它会抛出“找不到远程服务器”错误。导致问题的代码如下:

public class MyWebClient
{
  private HttpWebRequest _request;
  private Uri _uri;
  private AsyncOperation _asyncOp;

  public MyWebClient(Uri uri)
  { 
    _uri = uri; 
  }

  public void Start(XElement data)
  {
    _asyncOp = AsyncOperationManager.CreateOperation(null);
    _data = data;
    _request = (HttpWebRequest)WebRequest.Create(_uri);
    _request.Method = "POST";
    _request.BeginGetRequestStream(new AsyncCallback(BeginRequest), null);
  }

  private void BeginRequest(IAsyncResult result)
  {
    Stream stream = _request.EndGetRequestStream(result);
    using (StreamWriter writer = new StreamWriter(stream))
    {
      writer.Write(((XElement)_data).ToString());
    }
    stream.Close();
    _request.BeginGetResponse(new AsyncCallback(BeginResponse), null);
  }

  private void BeginResponse(IAsyncResult result)
  {
    HttpWebResponse response = (HttpWebResponse)_request.EndGetResponse(result);
    if (response != null)
    {
       //process returned data
        ...
    }
  }
  ...
 }

简而言之,上面的代码将一些XML数据发送到Web服务器(到ASP.NET MVC控制器)并获取已处理的数据。它在我使用Internet Explorer 8时有效。有人可以解释一下Google Chrome的问题吗?

1 个答案:

答案 0 :(得分:0)

我发现问题与使用谷歌浏览器的ASP.NET MVC路由处理有关,因此提出了一个新问题:

ASP.NET MVC routing issue with Google Chrome client