可能性のある認証の問題? 4 SilverlightのWebクライアントを経由してJSONのロード
-
11-09-2019 - |
質問
私は、Silverlight 4で遊んでいる、と私私のページが読み込まが、私が呼ぶとき
beginGet("my/people/", new OpenReadCompletedEventHandler(continueLoadStamData));
私は次のように定義されていること。
private void beginGet(string endpoint, OpenReadCompletedEventHandler callback)
{
WebClient wc = new WebClient();
wc.Credentials = new NetworkCredential(username, password);
wc.OpenReadCompleted += callback;
wc.OpenReadAsync(new Uri(baseURL + endpoint));
}
とcontinueLoadStamData()
void continueLoadStamData(object sender, OpenReadCompletedEventArgs e)
{
JsonObject root = (JsonObject)JsonObject.Load(e.Result);
}
私の問題は、私はe.Resultに得るとき、それは例外をスローということです。それは私が私がWebRequest req = ...; req.Credentials = new NetworkCredential(username, password)
を使用しようとしたときと同じ得る例外ではあります:
{System.Reflection.TargetInvocationException: An exception occurred during the operation, making the result invalid. Check InnerException for exception details. ---> System.Net.WebException: An exception occurred during a WebClient request. ---> System.NotImplementedException: This property is not implemented by this class.
at System.Net.WebRequest.set_Credentials(ICredentials value)
at System.Net.WebClient.GetWebRequest(Uri address)
at System.Net.WebClient.OpenReadAsync(Uri address, Object userToken)
--- End of inner exception stack trace ---
--- End of inner exception stack trace ---
at System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary()
at System.Net.OpenReadCompletedEventArgs.get_Result()
at JSONSample.MainPage.continueLoadStamData(Object sender, OpenReadCompletedEventArgs e)
at System.Net.WebClient.OnOpenReadCompleted(OpenReadCompletedEventArgs e)
at System.Net.WebClient.OpenReadOperationCompleted(Object arg)}
私は基本認証が実装されており、私の要求が軌道に乗ることを確認することができますどのように、何が起こっているの任意のアイデアを持っていますか?
乾杯
ニク
解決
ここマークモンスターのポストに基づいて、 にあなたのbeginGetメソッドのコードのいくつかの行を逃しています。それは次のようになります。
private void beginGet(string endpoint, OpenReadCompletedEventHandler callback)
{
WebRequest.RegisterPrefix("http://", System.Net.Browser.WebRequestCreator.ClientHttp);
WebClient wc = new WebClient();
wc.Credentials = new NetworkCredential(username, password);
wc.UseDefaultCredentials = false;
wc.OpenReadCompleted += callback;
wc.OpenReadAsync(new Uri(baseURL + endpoint));
}
あなただけのサーバからJSONを取得しようとしている場合は、また、あなたは物事を単純化するかもしれないDownloadStringAsyncの代わりOpenReadAsyncを使用することができる必要があります。
所属していません StackOverflow