Error: XmlException was unhandled by user code
Error: XmlException was unhandled by user code
我遇到如下错误:"An exception of type 'System.Xml.XmlException' occurred in System.Xml.dll but was not handled in user code"
在我的程序中,我使用了来自该站点的服务引用:http://www.oorsprong.org/websamples.countryinfo/CountryInfoService.wso 并且当 运行 程序时,它会阻止我访问字符串。
XML文件:(我只想取sName)
<ArrayOftContinent>
<tContinent>
<sCode>AF</sCode>
<sName>Africa</sName>
</tContinent>
</ArrayOftContinent>
代码如下:
org.oorsprong.www.CountryInfoService myWS3 = new org.oorsprong.www.CountryInfoService();
string str = Convert.ToString(myWS3.ListOfContinentsByName());
XmlDocument doc = new XmlDocument();
doc.LoadXml(str); /*It stops me here*/
你能帮我解决这个问题吗?
提前致谢!
您的 wso 正在返回大陆对象,而不是 xml 字符串。阅读定义:
http://www.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?op=ListOfContinentsByName
您想做这样的事情:
org.oorsprong.www.CountryInfoService myWS3 = new org.oorsprong.www.CountryInfoService();
var continents = myWS3.ListOfContinentsByName();
foreach (var continent in continents)
Debug.WriteLine(continent.sName)
我遇到如下错误:"An exception of type 'System.Xml.XmlException' occurred in System.Xml.dll but was not handled in user code"
在我的程序中,我使用了来自该站点的服务引用:http://www.oorsprong.org/websamples.countryinfo/CountryInfoService.wso 并且当 运行 程序时,它会阻止我访问字符串。
XML文件:(我只想取sName)
<ArrayOftContinent>
<tContinent>
<sCode>AF</sCode>
<sName>Africa</sName>
</tContinent>
</ArrayOftContinent>
代码如下:
org.oorsprong.www.CountryInfoService myWS3 = new org.oorsprong.www.CountryInfoService();
string str = Convert.ToString(myWS3.ListOfContinentsByName());
XmlDocument doc = new XmlDocument();
doc.LoadXml(str); /*It stops me here*/
你能帮我解决这个问题吗? 提前致谢!
您的 wso 正在返回大陆对象,而不是 xml 字符串。阅读定义: http://www.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?op=ListOfContinentsByName
您想做这样的事情:
org.oorsprong.www.CountryInfoService myWS3 = new org.oorsprong.www.CountryInfoService();
var continents = myWS3.ListOfContinentsByName();
foreach (var continent in continents)
Debug.WriteLine(continent.sName)