我在silverlight中使用浏览器外应用程序。
我在使用下面提到的代码加载xml文件时遇到问题。
string contentUri = Application.Current.Host.Source
.AbsoluteUri;
var contentUri1 = contentUri.Substring(0, contentUri.LastIndexOf("/")) + "/Hello1.xml";
WebClient wc = new WebClient();
wc.OpenReadCompleted+=(open,read)=>
{
string content;
using (StreamReader reader = new StreamReader(read.Result,Encoding.Unicode))
{
byte[] m_Bytes = ReadToEnd(read.Result);
string s = Encoding.UTF8.GetString(m_Bytes, 0, m_Bytes.Length);
}
};
wc.DownloadProgressChanged
+= (chang,dh)=>
{
};
wc.OpenReadAsync(new Uri(contentUri));
我的xml文件中包含
<Root>
<element>FirstElement</element>
</Root>
我得到了垃圾值作为输出。有人能帮助我如何下载原始xml内容吗?
当您在浏览器外模式下调用web客户端调用时,它假设您已经创建了RootVisual,因为web客户端显然将在其Dispatcher上运行。否则,您将不会得到服务器的响应,而且奇怪的是,甚至不会抛出异常!!
无论如何,Jeremy的这篇文章解释了细节:
http://csharperimage.jeremylikness.com/2010/05/webclient-and-deploymentcatalog-gotchas.html