//转换钮的事件 void btnConvert_Click(object sender, EventArgs e) { this.txtTemp.ResignFirstResponder(); switch (SegService.SelectedSegment) { //使用SOAP case 0: var converter1 = new SOAPConvert.TempConvert(); if (SegType.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 (SegType.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 (SegType.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 (SegType.SelectedSegment == 0) { this.lblResult.Text = content["Fahrenheit"].ToString(); } else { this.lblResult.Text = content["Celsius"].ToString(); } } } break; } }
//转换钮的事件 void btnConvert_Click(object sender, EventArgs e) { this.txtTemp.ResignFirstResponder(); switch (SegService.SelectedSegment) { //使用SOAP case 0: var converter1 = new SOAPConvert.TempConvert(); if (SegType.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 (SegType.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 (SegType.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 (SegType.SelectedSegment == 0) { this.lblResult.Text = content["Fahrenheit"].ToString(); } else { this.lblResult.Text = content["Celsius"].ToString(); } } } break; } }