Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

Results 1 to 7 of 7

Thread: Using WebService function

  1. #1

    Using WebService function

    Hey guys, I've created the following webservice:

    Code:
    using System;
    using System.Web;
    using System.Collections;
    using System.Web.Services;
    using System.Web.Services.Protocols;
    using System.Xml;
    using System.Xml.XPath;
    
    
    /// <summary>
    /// Summary description for users
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class users : System.Web.Services.WebService {
        userManager usr;
        public users () {
            usr = new userManager();
            
        }
    
        [WebMethod]
        public bool login(string username, string password)
        {
            if (this.usr.login(username, password) == true)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    
        [WebMethod]
        public string HelloWorld() {
            return "Hello World";
        }
        
    }
    
    class userManager
    {
        private string xmlfile;
        public XmlDocument doc;
        private XPathNavigator nav;
    
        public userManager()
        {
            instantiate();
            xmlfile = @"C:\web\webservices\WS\users.xml";
            doc.Load(xmlfile);
        }
    
        private void instantiate()
        {
            this.doc = new XmlDocument();
            nav = doc.CreateNavigator();
        }
    
        public bool login(string usr, string pass)
        {
            if (doc.SelectSingleNode("/users/user[username='" + usr + "']").SelectSingleNode("password").InnerText == pass)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    
    }
    This works fine and I can access it with my browser.
    I then added a reference to it in my visual c# project.

    The problem is that I don't know how to send the username and password to the function and check the result.

    A little help? Thanks!
    Web Design and Web Development blog
    Designer Notice: Browser List for design compatibility

  2. #2
    I've figured it out
    Code:
     remoteLogin.usersSoapClient usr = new xpath.remoteLogin.usersSoapClient();
                
                if (usr.login("efg", "fail") == true)
                {
                    Console.WriteLine("Logged in");
                }
                else
                {
                    Console.WriteLine("Not");
                }
    Web Design and Web Development blog
    Designer Notice: Browser List for design compatibility

  3. #3
    Okay my new problem is that because web services are stateless the username will not get saved = users don't stay logged in.
    will I have to send my username and password to every function or is there some other way?
    I don't think you can use sessions with web services can you?
    Web Design and Web Development blog
    Designer Notice: Browser List for design compatibility

  4. #4
    You could set a cookie to keep state, but you should look into the security implications of this also.

  5. #5
    How can you use cookies with desktop applications?
    Web Design and Web Development blog
    Designer Notice: Browser List for design compatibility

  6. #6
    You could create a temporary sessionID. I don't think cookies will work, but I've never tried that

    Great, now even Kirupa is { facebooking | twittering }

  7. #7
    So how would I do that? ha.
    Would it mean that every function would need a parameter for the sessionid?
    Web Design and Web Development blog
    Designer Notice: Browser List for design compatibility

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012