Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml C#Html编码错误_C#_Asp.net_Xml_Soap - Fatal编程技术网

Xml C#Html编码错误

Xml C#Html编码错误,c#,asp.net,xml,soap,C#,Asp.net,Xml,Soap,我使用一个方法——getComments——来检索用户输入,并将xmlElements用于我的soap Web服务。在调用该方法时,我收到一个空引用,VStudio要求我创建一个新对象。以下是我收到错误的代码: XmlElement msgbodyElement = (XmlElement)messageElement.ChildNodes[0]; msgbodyElement.InnerText = HttpUtility.UrlEncode (getCommentInform

我使用一个方法——getComments——来检索用户输入,并将xmlElements用于我的soap Web服务。在调用该方法时,我收到一个空引用,VStudio要求我创建一个新对象。以下是我收到错误的代码:

XmlElement msgbodyElement = (XmlElement)messageElement.ChildNodes[0];
        msgbodyElement.InnerText = HttpUtility.UrlEncode (getCommentInformation()); 
想法?特定错误:System.NullReferenceException:对象引用未设置为对象的实例


谢谢。

从这段代码来看,messageElement为null,或者它没有子节点,或者getCommentInformation在内部引发了异常。

我不知道为什么这被否决了两次,也不知道为什么人们觉得他们必须在网上听起来粗鲁……调试是第一步是吗


感谢Jim提醒我检查节点,但事实证明并非如此。在代码中我发现这是代码的顺序。

这是我收到错误的代码
,是的,那么这两个代码中的哪一个引发了异常?确切的例外情况是什么?使用调试器…哇…抱歉。。例外情况出现在getComments()的msgbodyElement中……谢谢。我甚至没有想到检查子节点。我试试看。谢谢你的好意,我对这个有点陌生。