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的回报。我怎么能做到这一点?
答案 0 :(得分:-1)
您可以使用string.IndexOf
和string.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;
}
我希望我能帮助你。