Saturday 15 September 2012

c# - Possible authentication problem? Loading a JSON via WebClient in Silverlight 4 -


I have been playing with Silverlight 4, and when my page loads, I'd call

< Pre> StartGate ("me / people /", new openred compliant Avent handler (loadloaded data released));

I have defined as the

  private void beginGet (string endpoint, OpenReadCompletedEventHandler callback) {WebClient WC = new WebClient (); Wc.Credentials = New network credentials (username, password); Wc.OpenReadCompleted + = Callback; Wc.OpenReadAsync (new url (baseURL + endpoint)); }  

and continueLoadStamData ()

  void continueLoadStamData (object sender, OpenReadCompletedEventArgs e) {JSONObject root = (JSONObject) JsonObject.Load (e.Result) ; }  

My problem is that when I e Receives I, it throws an exception, it had tried to do the same exception that I get when I use WebRequest req = ...; Req.Credentials = new network credentials (username, password) :

  {System.Reflection.TargetInvocationException: during an exceptional operation, result invalid. Check the inner exception for the exception details. --- & gt; System.Net.WebException: An exception occurred during a web client request. --- & gt; System.NotImplementedException: This property has not been implemented by this class. System.Net.WebRequest.set_Credentials (ICredentials Price) on System.Net.WebClient.OpenReadAsync on System.Net.WebClient.GetWebRequest (URI address) at (URI address, object userToken) --- the end of the inner exception stack trace - --- End of the internal exception stack trace --- on System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIf () System.Net.OpenReadCompletedEventArgs.get_Result () JSONSample.MainPage.continueLoadStamData (Object Sender, OpenReadCompletedEventArgs e) on System.Net. WebClient.OnOpenReadCompleted (OpenReadCompletedEventArgs e) on System.Net.WebClient.OpenReadOperationCompleted (object arguments)}  

Have any idea of ​​what's going on, how I believe Land that can make basic authentication

Nick

P > Depending on you, your lines are missing some lines of code in the gate method.

  Private zero startGet (string endpoint, OpenReadCompletedEventHandler callback) {WebRequest.RegisterPrefix: something like this should be done ("http: //", System.Net.Browser.WebRequestCreator.ClientHttp) ; Webclient wc = new webclient (); Wc.Credentials = New network credentials (username, password); Wc.UseDefaultCredentials = false; Wc.OpenReadCompleted + = Callback; Wc.OpenReadAsync (new url (baseURL + endpoint)); }  

In addition, if you are just trying to get JSON from the server, then you should be able to use OpenStoreAsync instead of OpenReadAsync to make things easier. .


No comments:

Post a Comment