Web Service in Windows Form C#


I have added a web service to my windows project. The service is one that you can use to take a zip code and return the City and State.

I have on my form 3 text boxes 1 for Zip, City and State and a button that I want to use to run the process that will take the zip in txtboxzip and return the city and state.

I am using the web service

I have tried several ways of doing this. I think I am close, but always an error like the last.

"cannot implicitly convert type 'System.xml.xmlnode' to 'string'"

Any help would be great.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Robert SchuttSoftware EngineerCommented:
Try using something like this:
            ServiceReference1.USZipSoapClient z = new ServiceReference1.USZipSoapClient("USZipSoap");
            XmlNode x = z.GetInfoByZIP(textBox1.Text);
            if (x.HasChildNodes) {
                textBox2.Text = x.SelectSingleNode("//CITY").InnerText;
                textBox3.Text = x.SelectSingleNode("//STATE").InnerText;
            } else {
                textBox2.Text = "N/A";
                textBox3.Text = "N/A";

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Carl TawnSystems and Integration DeveloperCommented:
If you want something a bit more raw, that doesn't require adding a service reference, you can use:
            string url = string.Format(

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.Method = "GET";

            HttpWebResponse resp = (HttpWebResponse)request.GetResponse();
            StreamReader sr = new StreamReader(resp.GetResponseStream());

            XDocument doc = XDocument.Parse(sr.ReadToEnd());

            var data = (from n in doc.Root.Elements("Table")
                    select new {
                        City = (string)n.Element("CITY"),
                        State = (string)n.Element("STATE")

            CityText.Text = data.City;
            StateText.Text = data.State;

Open in new window

riley00Author Commented:
Awesome, Thanks for your help!!!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.