How to get web service values in client app?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tookerello
    New Member
    • May 2010
    • 5

    How to get web service values in client app?

    hi how can i view the the web service result in my client app?
    the web service is:

    Code:
    public struct SecurityInfo
    {
        public string location;
        public string areacode;
    }
    [WebService(Namespace = "http://192.168.1.6/WebService/Service.asmx",
    Description = "A Simple Web Calculator Service",
    Name = "CalculatorWebService")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    
    public class Service : System.Web.Services.WebService
    {
        private SecurityInfo Security;
    
        public Service()
        {
            Security.location = "";
            Security.areacode = "";
        }
        private void AssignValues(string Code)
        {
            
            Security.location = Code;      
    
            XmlDocument doc = new XmlDocument();
    
            doc.Load("G:\\Server\\App_Code\\phoneBook.xml");
            XmlNodeList towns = doc.GetElementsByTagName("town");
            foreach (XmlNode town in towns)
            {
                if (Code.Equals(town.ChildNodes[0].Value))
                {
                    string resq = town.ParentNode.Attributes["code"].Value;
                    string tmp = ("The area code of " + Code + "    " + "is " + "    " + resq.ToString());
                    Security.areacode = tmp;
                }
            }
        }
        [WebMethod(Description = "This method call will get the area code for the given town.", EnableSession = false)]
        public SecurityInfo GetSecurityInfo(string Code)
        {
            AssignValues(Code);
            SecurityInfo SecurityDetails = new SecurityInfo();
            SecurityDetails.location = Security.location;
            SecurityDetails.areacode = Security.areacode;
            return SecurityDetails;
        }
    }
    and the client app is:

    Code:
     private string getResult(string input)        {            SmartDeviceProject2.webser.CalculatorWebService myservice = new SmartDeviceProject2.webser.CalculatorWebService();                        string a = "";            string result = null;            result = "AREACODE OF" + input + "IS" + myservice.GetSecurityInfo(a);            return result;                    }        private void button1_Click(object sender, EventArgs e)        {              lstResult.Items.Add(getResult(txtInput.Text).ToString());        }
Working...