【发布时间】:2023-03-29 16:10:01
【问题描述】:
我正在尝试在我的肥皂程序中实现秒表方法。该方法将启动秒表并在程序加载后停止秒表,我想在 asmx 页面上显示启动和停止之间经过的时间。
下面是我试图实现秒表方法的代码:
public class WebService1 : System.Web.Services.WebService
{
static private Authenticator auth = new Authenticator();
Stopwatch sw = new Stopwatch();
[WebMethod]
public string Authenticate(string username, string password)
{
sw.Start();
if (string.IsNullOrWhiteSpace(username) && string.IsNullOrWhiteSpace(password))
{
return "Please enter a username and password";
}
if (string.IsNullOrWhiteSpace(username))
{
return "Please enter your username!";
}
if (string.IsNullOrWhiteSpace(password))
{
return "Please enter your password!";
}
//Assigning the username and password variables to a bool called isvalid
bool isvalid = auth.authenticated(username, password);
{
if (isvalid)//Not using == because im not comparing
{
return "Authenticated!";
}
else
{
return "Not Authenticated!";
}
}
sw.Stop();
long time = sw.ElapsedMilliseconds;
return time.ToString();
// long time = sw.ElapsedMilliseconds;
// return time.ToString();
}
}
}
我的问题是 - 是否可以按照我的要求做,如果可以的话,我到目前为止是正确的,因为它不起作用! (是的,我知道 .asmx 是旧版)
【问题讨论】:
标签: c# web-services soap asmx stopwatch