C# 需要从ASP.NET Web服务中删除xml标记

C# 需要从ASP.NET Web服务中删除xml标记,c#,asp.net,web-services,C#,Asp.net,Web Services,这个方法应该返回密码,不带任何XML标记。纯文本。上面的图片是从webservice返回的。如何实现这一点?您可以使用string.IndexOf和string.LastIndexOf方法,然后生成一个子字符串。这个对我很管用 namespace CheckPassword { /// <summary> /// Summary description for Service1 /// </summary> // To allow thi

这个方法应该返回密码,不带任何XML标记。纯文本。上面的图片是从webservice返回的。如何实现这一点?

您可以使用string.IndexOf和string.LastIndexOf方法,然后生成一个子字符串。这个对我很管用

namespace CheckPassword
{
    /// <summary>
    /// Summary description for Service1
    /// </summary>

    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class Service1 : System.Web.Services.WebService
    {

        [WebMethod]
        public string CheckPass(string globalid)
        {

            string conStr1 = System.Configuration.ConfigurationSettings.AppSettings["questConStr"];

            string query1 = "select PASSWORD from TM_Roles where GLOBAL_ID='" + globalid + "'";

            SqlConnection con1 = new SqlConnection(conStr1);
            con1.Open();
            SqlCommand command1 = new SqlCommand(query1, con1);
            DataSet ds = new DataSet();
            SqlDataAdapter oda = new SqlDataAdapter(command1);
            oda.Fill(ds, "reading");

            DataRow dr = ds.Tables[0].Rows[0];

            string password = dr["PASSWORD"].ToString();


            string s = password;


            /* the next three lines are supposed to remove the xml tags */
            System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.BinaryWrite(encoding.GetBytes(s));

            con1.Close();
            return s;
        }
    }
}

我希望我能帮助你

您是否实际使用了您的Web服务并返回xml?@Sam consumered?Web服务的客户端构建时没有XML标记。这里的一名实习生更改了一些代码,我无法恢复到旧的实现。更糟糕的是,客户端构建已经是分布式的。你说它返回xml,那么你真的创建了一个客户端并调用了服务并查看了xml吗?
    private string RemoveXmlTags(string  input)
    {
        string  output;
        int     firstIndex;
        int     lastIndex;

        firstIndex = input.IndexOf("\">");
        lastIndex = input.LastIndexOf("<");
        //you need to move the count of the chars you looked for in IndexOf to the start of the string
        output = input.Substring(firstIndex + 2, lastIndex - firstIndex-2);

        return output;
    }