2012-03-15 3 views
0

こんにちは、私はウェブサービスからデータを取得する必要があります&それらをテキストブロックに入れてください。次のコードで空のテキストブロックを表示します。コードに問題がありますか? ????ウェブサービスのテキストブロックデータ

public info() 
    { 

     InitializeComponent(); 

     WebClient inf = new WebClient(); 
     // client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted); 

     inf.DownloadStringCompleted+=new DownloadStringCompletedEventHandler(inf_DownloadStringCompleted); 


     //name.Text = 
    } 
    public void inf_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) 
    { 
     string pass = mp.passwordBox1.Password; 

     string id = mp.tx.Text; 
     string url = "http://82.212.89.6:888/mob/resources/stdInfo/authenticate/" +id + "/" +pass + "/1/570322308ce1121cba1b93f5acc9ebd4733ef2bca90ef942a2cfa224f0aa08dc/1"; 

     XElement xx = XElement.Parse(url); 
     string m= xx.Element("userId").Value; 

     name.Text = m; 
     } 
+1

が見えます。 – reinierpost

+0

'xmlreader'を使用して結果を読み込み、その内容を解析します。 –

+0

私はxmlreaderからオブジェクトを定義し、それを任意のクラスオブジェクトとして使用して値を呼び出します。 –

答えて

0

あなたはinfオブジェクトのDownloadStringAsyncを呼び出していません。 inf_DownloadStringCompletedeパラメータを使用していません。 Webサービスを消費ANデータを解析するために

+0

plzしかし、私はこれをどうすればいいのか分かりませんか?なぜ私はeを使うべきです –

+0

@ワラNawras 'e.Result'はダウンロードしたデータを含んでいます。詳細はこちらhttp://msdn.microsoft.com/en-us/library/system.net.downloadstringcompletedeventargs.aspx – clearpath

0

:URLを別れの代わりに、その内容をしているよう

String baseUri = “your service URI"; 
    WebClient wc = new WebClient(); 

    public MainPage() 
    { 
     InitializeComponent(); 
    wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler  (wc_downloadstringcompleted); 
    // event handler that will handle the ‘downloadstringsompleted’ event 

      wc.DownloadStringAsync(new Uri(baseUri));  
    // this method will download your string URI asynchronously  

    } 


void wc_downloadstringcompleted(Object sender, DownloadStringCompletedEventArgs e) 
    { 
      // method will get fired after URI download completes 
      // writes your every code here 

      using (XmlReader reader = XmlReader.Create(new StringReader(xmlString))) 
      {   
       while (reader.Read()) 
       { 
        switch (reader.NodeType) 
        { 
         case XmlNodeType.Element: 
          if (reader.Name = "userId") 
            string str1 = reader.value(); 
          break; 
        } 
       } 
      } 

     name.text = str1; 
    }