0

在此处输入图像描述

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;
        }
    }
}

此方法应该返回密码,不带任何 XML 标记。只是纯文本。上图是从webservice返回的。我怎样才能做到这一点?

4

1 回答 1

-1

你可以用string.IndexOfandstring.LastIndexOf方法来做,然后只做一个子字符串。这个对我来说很好用。

    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;
    }

我希望我能帮助你。

于 2013-07-05T11:40:20.617 回答