Exemplo n.º 1
0
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            string value;
            string type;
            NavigationContext.QueryString.TryGetValue("type", out type);
            NavigationContext.QueryString.TryGetValue("value", out value);

            UsZip.USZipSoapClient c = new UsZip.USZipSoapClient();

            USZipSoapClient u = new USZipSoapClient();

            switch(type){
                case "Zip":
                    u.GetInfoByZIPAsync(value);
                    u.GetInfoByZIPCompleted += new EventHandler<GetInfoByZIPCompletedEventArgs>(u_GetInfoByZIPCompleted);
                break;
                case "Area":
                    u.GetInfoByAreaCodeAsync(value);
                    u.GetInfoByAreaCodeCompleted += new EventHandler<GetInfoByAreaCodeCompletedEventArgs>(u_GetInfoByAreaCodeCompleted);
                break;

                case "City":
                u.GetInfoByCityAsync(value);
                u.GetInfoByCityCompleted += new EventHandler<GetInfoByCityCompletedEventArgs>(u_GetInfoByCityCompleted);
                break;

                case "State":
                u.GetInfoByStateAsync(value);
                u.GetInfoByStateCompleted += new EventHandler<GetInfoByStateCompletedEventArgs>(u_GetInfoByStateCompleted);
                break;
            }
        }
        public static USZipSoap CreateSoapClient()
        {
            var client = new USZipSoapClient();

            /*Configure your client */
            return(client);
        }
    protected void btn_Click(object sender, EventArgs e)
    {
        //Web Reference: http://www.webservicex.net/uszip.asmx?WSDL 
        string txt = txtZip.Text;
        USZipSoapClient z = new USZipSoapClient("USZipSoap");
        XmlDocument x = new XmlDocument();

        string a = z.GetInfoByZIP(txt).InnerXml;
        x.LoadXml(a);

        XmlNodeList city = x.GetElementsByTagName("CITY");
        XmlNodeList state = x.GetElementsByTagName("STATE");
        XmlNodeList zip = x.GetElementsByTagName("ZIP");
        XmlNodeList area_code = x.GetElementsByTagName("AREA_CODE");

        rt.InnerHtml = "<br />City: " + city.Item(0).InnerText + "<br />State: " + state.Item(0).InnerText + "<br />Zip Code: " + zip.Item(0).InnerText + "<br />Area Code: " + area_code.Item(0).InnerText;
    }
Exemplo n.º 4
0
 private void GetCityState(string zip)
 {
     //Try to access web service and get the city and state from the supplied zipcode.
     try
     {
         var soapClient = new USZipSoapClient("USZipSoap");
         var allNodes = soapClient.GetInfoByZIP(zip);
         var x = XDocument.Parse(allNodes.InnerXml);
         var city = x.Descendants("CITY").Select(m => m.Value);
         var state = x.Descendants("STATE").Select(m => m.Value);
         txtCity.Text = city.First();
         txtState.Text = state.First();
         btnSubmit.Enabled = true;
     }
     catch (XmlException)
     {
         //The zip code given was invalid. Allow user to retry.
         txtCity.Text = "";
         txtState.Text = "";
         windowManager.RadAlert("Invalid Zip Code. Check zip code and validate again.", 250, 125, "Zip Code Invalid", "");
     }
     catch (EndpointNotFoundException)
     {
         //Web service not available. Allow user to manually enter information.
         windowManager.RadAlert("Zip Code Lookup is unavailable. Please enter city and state manually.", 250, 125, "Zip Look-up Unavailable", "");
         txtCity.Enabled = true;
         txtCity.ReadOnly = false;
         txtState.Enabled = true;
         txtState.ReadOnly = false;
         btnValidateZip.Enabled = false;
         btnSubmit.Enabled = true;
     }
 }