2012-04-02 2 views
0

Как сделать HTTP-доступ в silverlight (Winphone)?Как сделать HTTP-доступ в silverlight (Winphone)

Мой код не работает (выдает исключения)

я получаю следующие исключения:

A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll 
A first chance exception of type 'System.Net.ProtocolViolationException' occurred in System.Windows.dll 
A first chance exception of type 'System.Net.ProtocolViolationException' occurred in System.Windows.dll 
A first chance exception of type 'System.MissingMethodException' occurred in mscorlib.dll 
A first chance exception of type 'System.Net.ProtocolViolationException' occurred in System.Windows.dll 

Вот код:

public Boolean getAnnouncements() 
    { 
     try 
     { 
      string url = "https://server.james-bennet.com:8443/BookingSystem/Announcement"; 
      HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); 
      request.Method = "GET"; 
      request.Accept = "application/json"; 
      request.ContentType = "application/json; charset=utf-8"; 

      HttpWebResponse response = request.BeginGetResponse(new AsyncCallback(ReadCallback), request) as HttpWebResponse; 
      return true; 
     } 
     catch (Exception e) 
     { 
      System.Console.WriteLine(e.ToString()); 
      return false; 
     } 
    } 

    private void ReadCallback(IAsyncResult asynchronousResult) 
    { 
     try 
     { 
     HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState; 
     HttpWebResponse response =(HttpWebResponse)request.EndGetResponse(asynchronousResult); 

     using (StreamReader streamReader1 = new StreamReader(response.GetResponseStream())) 
     { 
      string resultString = streamReader1.ReadToEnd(); 
      System.Console.WriteLine(resultString); 
     } 
        } 
     catch (Exception e) 
     { 
      System.Console.WriteLine(e.ToString()); 
     } 
    } 

ответ

0

Вы убедились, что у вас есть

<Capability Name="ID_CAP_NETWORKING"/> 

настроен в вашем файле WMAppManifest.xml?

Смежные вопросы