将数据集添加到XML文档中作为webservice的参数

时间:2015-08-05 05:37:05

标签: c# xml web-services

我创建了一个Web服务方法,该方法将Dataset作为参数,并且必须以XMLDocument的形式发送参数,而不是使用以下代码的任何其他方式:

public static bool UpdateUnitMst(string isLive, string EmpId, string EmpNameFull, DataSet dst, string where)
{
    XmlDocument soapEnvelopeXml = new XmlDocument();
    string xmlToLoad = @"<?xml version=""1.0"" encoding=""utf-8""?>
                        <soap:Envelope 
                                    xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"" 
                                    xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" 
                                    xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
                        <soap:Body>
                        <UpdateUnitMst xmlns=""http://abc/services/"">"
                            + "<isLive>" + isLive + "</isLive>"
                            + "<EmpId>" + EmpId + "</EmpId>"
                            + "<EmpNameFull>" + EmpNameFull + "</EmpNameFull>"
                            + "<dst>" + dst + "</dst>"
                            + "<where>" + where + "</where>"
                    + "</UpdateUnitMst>"
                    + "</soap:Body>"
                    + "</soap:Envelope>";
    soapEnvelopeXml.LoadXml(xmlToLoad);
    try
    {
        HttpWebRequest request = GetWebRequest();
        using (Stream stream = request.GetRequestStream())
        {
            soapEnvelopeXml.Save(stream);
        }
        using (WebResponse response = request.GetResponse())
        {
            using (StreamReader rd = new StreamReader(response.GetResponseStream()))
            {
                string xmlString = rd.ReadToEnd();
                XmlDocument soapResult = new XmlDocument();
                soapResult.LoadXml(xmlString);

                string result = soapResult.GetElementsByTagName("UpdateUnitMstResult")[0].InnerText;

                if (result != "success")
                    return false;
            }
        }
    }
    catch (Exception) { }
    return true;
}

请帮助我,我被困了几天。 提前谢谢。

0 个答案:

没有答案