Asp.net 如何使用此web服务?
这是我第一次创建web服务。我不确定我的实现是否不正确,但我正试图像类一样使用。问题是,当我试图消费时,我会感到困惑,无法设置属性的值 这是web服务Asp.net 如何使用此web服务?,asp.net,c#-4.0,Asp.net,C# 4.0,这是我第一次创建web服务。我不确定我的实现是否不正确,但我正试图像类一样使用。问题是,当我试图消费时,我会感到困惑,无法设置属性的值 这是web服务 public class Service1 : System.Web.Services.WebService { private bool _isUserActive { get; set; } private bool _isCredentialValid { get; set; } public string emai
public class Service1 : System.Web.Services.WebService
{
private bool _isUserActive { get; set; }
private bool _isCredentialValid { get; set; }
public string email { get; set; }
public string pass { get; set; }
public int customerID { get; set; }
[WebMethod]
public bool VerifyUserCredential()
{
bool result = false;
PURLDataContext purl = new PURLDataContext();
try
{
var res = purl.Sel_User(email.ToLower(), pass);
if (res != null)
result = true;
_isUserActive = true;
_isCredentialValid = true;
}
catch (Exception ex)
{
if (ex.Message == "Account is inactive, please contact your administrator!")
{
_isUserActive = false;
_isCredentialValid = false;
}
else
_isCredentialValid = false;
//Invalid credentials.
}
return result;
}
[WebMethod]
public ArrayList retrieveCustomerInfo()
{
ArrayList customerInfo = new ArrayList();
string validate = "Please Validate";
if (_isCredentialValid)
{
PURLDataContext purl = new PURLDataContext();
var customer = purl.Sel_Recipient(customerID);
foreach (var c in customer)
{
customerInfo.Add(c);
}
}
else
customerInfo.Add(validate);
return customerInfo;
}
}
以下是我试图消费的东西
PURLServices.Service1SoapClient webserv = new Service1SoapClient();
bool result;
ArrayOfAnyType array = new ArrayOfAnyType();
webserv.email = "email@email.com";
webserv.pass = "pass";
webserv.customerID = 12345;
result = webserv.VerifyUserCredential();
array = webserv.retrieveCustomerInfo();
感谢您的帮助///p>您不想尝试使用这样的属性。您的方法应该更像这样:
public bool VerifyUserCredential(string userName, string password)
{
// method body here
}
您可能希望返回服务器将缓存的某种访问令牌。然后可以将其传递到其他方法中,以表明用户有效。您不应该创建ASMX web服务。微软认为它们是传统技术。所有新开发都应该使用WCF.Wow。您也不应该使用自.NET 2.0以来就已弃用的ArrayList,而应该使用List,并且永远不要与异常对象的Message属性进行比较。@JohnSaunders,thnx供您参考。WCF非常快速,而且更容易实现。