开发者

How to consume this web service?

This is my first time creating a web service. I am not sure if my implementation is incorrect, but I am trying to use much like a class. The problem is that when I am trying to consume I am getting confused and not being able to set the values of the properties.

here is the web service.

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;

    }
}

Here is what I am trying to do to consume.

        PURLServices.Service1开发者_StackOverflow中文版SoapClient 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();

Thank you for any help/


You do not want to try to use properties like this. Your method should look more like this:

public bool VerifyUserCredential(string userName, string password)
{
 // method body here

}

Probably you would want to return an access token of some sort that the server will cache. This can then be passed into other methods to show that the user is valid.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜