我正在制作一个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"));
}
答案 0 :(得分:2)
更改
XmlDocument _xmlDoc = "./xmlfile.xml";
到
_xmlDoc = "./xmlfile.xml";