返回语句后,XmlDocument变为null

时间:2014-05-23 18:22:48

标签: c# xml

我正在制作一个HttpWebRequest,我将Xml文档发送到Web服务,并将请求的结果返回给单元测试。在return语句之后,Xml Document被取消了。为什么?

public class BaseTest
{
    public XmlDocument _xmlDoc; 

    public string CallWebService()
    {
    XmlDocument _xmlDoc = "./xmlfile.xml";

    /*Prepare HttpHeaders and make webservice call*/

    string result = reader.ReadToEnd().ToString();
    return result;//<-----_xmlDoc becomes null at this point. 

    }

}

[TestMethod]
public void TestWebService()
{
     string result = CallWebService();
     Assert.IsTrue(result.Contains("SUCCESS"));  
}

1 个答案:

答案 0 :(得分:2)

更改

XmlDocument _xmlDoc = "./xmlfile.xml";

_xmlDoc = "./xmlfile.xml";