C# 来自web服务的文本块数据
嗨,我需要从web服务获取数据并将它们放入文本块。到下一个代码时,它会给我空文本块。我的代码有问题吗C# 来自web服务的文本块数据,c#,windows-phone-7,C#,Windows Phone 7,嗨,我需要从web服务获取数据并将它们放入文本块。到下一个代码时,它会给我空文本块。我的代码有问题吗 您没有调用inf对象的DownloadStringAsync。您没有使用inf\u DownloadStringCompleted中的e参数来使用web服务并解析数据: String baseUri = “your service URI"; WebClient wc = new WebClient(); public MainPage() {
您没有调用
inf
对象的DownloadStringAsync
。您没有使用inf\u DownloadStringCompleted
中的e
参数来使用web服务并解析数据:
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;
}
看起来您正在分离url而不是其内容。使用
xmlreader
读取结果并解析其内容我从xmlreader中定义了一个对象,并使用它作为任何类对象调用值??plz,但我不明白如何才能做到这一点??我为什么要用e@ワラNawrase.Result
包含下载的数据。更多信息请点击这里
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;
}