Пример #1
0
        //�ϥΤ��P��Web Service �i���ഫ
        void btnCalculate_TouchUpInside(object sender, EventArgs e)
        {
            this.txttemp.ResignFirstResponder();

            switch (segService.SelectedSegment)
            {
                //�ϥ�SOAP
                case 0:
                   var converter1 = new soapconvert.TempConvert();
                   if (segMethod.SelectedSegment == 0)
                   { this.lblResult.Text = converter1.CelsiusToFahrenheit(txttemp.Text); }
                   else
                   { this.lblResult.Text = converter1.FahrenheitToCelsius(txttemp.Text); }
                    break;

                //�ϥ�WCF
                case 1:
                    var converter2 = new wcfconvert.WCFTempService();
                   if (segMethod.SelectedSegment == 0)
                   { this.lblResult.Text = converter2.CelsiusToFahrenheit(txttemp.Text); }
                   else
                   { this.lblResult.Text = converter2.FahrenheitToCelsius(txttemp.Text); }
                    break;

                //�ϥ�REST with JSON
                case 2:
                    string uri;
                    if (segMethod.SelectedSegment == 0){
                        uri = @"http://restfulconvert.azurewebsites.net/TempConvert.svc/ToF/" + txttemp.Text; }
                    else{
                        uri = @"http://restfulconvert.azurewebsites.net/TempConvert.svc/ToC/" + txttemp.Text; }

                    var request = HttpWebRequest.Create(uri);
                    request.Method = "GET";
                    request.ContentType = "application/json";

                    using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
                    {
                        using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                        {
                            var content = JObject.Parse(reader.ReadToEnd());
                            if (segMethod.SelectedSegment == 0)
                            {
                                this.lblResult.Text = content["Fahrenheit"].ToString();
                            }
                            else
                            {
                                this.lblResult.Text = content["Celsius"].ToString();
                            }
                        }
                    }
                    break;
            }
        }
Пример #2
0
        //使用不同的Web Service 進行轉換
        void btnCalculate_TouchUpInside(object sender, EventArgs e)
        {
            this.txttemp.ResignFirstResponder();

            switch (segService.SelectedSegment)
            {
            //使用SOAP
            case 0:
                var converter1 = new soapconvert.TempConvert();
                if (segMethod.SelectedSegment == 0)
                {
                    this.lblResult.Text = converter1.CelsiusToFahrenheit(txttemp.Text);
                }
                else
                {
                    this.lblResult.Text = converter1.FahrenheitToCelsius(txttemp.Text);
                }
                break;

            //使用WCF
            case 1:
                var converter2 = new wcfconvert.WCFTempService();
                if (segMethod.SelectedSegment == 0)
                {
                    this.lblResult.Text = converter2.CelsiusToFahrenheit(txttemp.Text);
                }
                else
                {
                    this.lblResult.Text = converter2.FahrenheitToCelsius(txttemp.Text);
                }
                break;


            //使用REST with JSON
            case 2:
                string uri;
                if (segMethod.SelectedSegment == 0)
                {
                    uri = @"http://restfulconvert.azurewebsites.net/TempConvert.svc/ToF/" + txttemp.Text;
                }
                else
                {
                    uri = @"http://restfulconvert.azurewebsites.net/TempConvert.svc/ToC/" + txttemp.Text;
                }

                var request = HttpWebRequest.Create(uri);
                request.Method      = "GET";
                request.ContentType = "application/json";

                using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
                {
                    using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                    {
                        var content = JObject.Parse(reader.ReadToEnd());
                        if (segMethod.SelectedSegment == 0)
                        {
                            this.lblResult.Text = content["Fahrenheit"].ToString();
                        }
                        else
                        {
                            this.lblResult.Text = content["Celsius"].ToString();
                        }
                    }
                }
                break;
            }
        }