public void WfcServiceHost_Http() { // Verify that we can create a service instance and then call it. WcfServiceHost host; host = new WcfServiceHost(new TestService()); try { host.AddServiceEndpoint(typeof(ITestService), @"binding=HTTP;uri=http://localhost:8008/Unit/Test.svc;settings=<wsHttpBinding><security mode=""None""/></wsHttpBinding>"); host.ExposeServiceDescription(null, null); host.Start(); TestServiceClient client; client = new TestServiceClient(new WSHttpBinding(SecurityMode.None), new EndpointAddress("http://localhost:8008/Unit/Test.svc")); client.Open(); try { client.Set("Hello World!"); Assert.AreEqual("Hello World!", client.Get()); } finally { client.Close(); } } finally { host.Stop(); } }
private void button1_Click(object sender, EventArgs e) { //refresh list TestServiceClient client = new TestServiceClient(); string[][] rows; try { client.Open(); rows = client.GetAllContacts(); client.Close(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); return; } dataGridView1.Rows.Clear(); for (int i=0;i<rows.Length;i++) { dataGridView1.Rows.Add(rows[i][0], rows[i][1]); } foreach (Control c in Controls) c.Enabled = true; }
static void Main(string[] args) { try { var client = new TestServiceClient(); client.Open(); string tmpString; int tmpInt; tmpString = client.GetData(13); WriteLine($"\"{tmpString}\""); tmpInt = client.Sum(2, 3); WriteLine(tmpInt); tmpInt = client.Subtract(25, 5); WriteLine(tmpInt); tmpInt = client.Multiply(2, 3); WriteLine(tmpInt); tmpInt = client.Divide(25, 5); WriteLine(tmpInt); CompositeType compositeType = client.GetDataUsingDataContract(new CompositeType { BoolValue = true, StringValue = "ClientStringValue" }); WriteLine($"{{BoolValue:{compositeType.BoolValue}, StringValue:\"{compositeType.StringValue}\"}}"); client.Close(); } catch (Exception eException) { WriteLine(eException.GetType().FullName + Environment.NewLine + "Message: " + eException.Message + Environment.NewLine + (eException.InnerException != null && !string.IsNullOrEmpty(eException.InnerException.Message) ? "InnerException.Message" + eException.InnerException.Message + Environment.NewLine : string.Empty) + "StackTrace:" + Environment.NewLine + eException.StackTrace); } }
static void Main(string[] args) { TestServiceClient client = new TestServiceClient(); client.Open(); int number = 12345600; Console.WriteLine(client.SearchName(number)); Console.ReadLine(); client.Close(); }
protected void BtnDoWorkClick(object sender, EventArgs e) { try { var client = new TestServiceClient(); client.Open(); client.DoWork(); client.Close(); } catch (Exception eException) { Debug.WriteLine(eException.GetType().FullName + Environment.NewLine + "Message: " + eException.Message + Environment.NewLine + (eException.InnerException != null && !string.IsNullOrEmpty(eException.InnerException.Message)? "InnerException.Message" + eException.InnerException.Message + Environment.NewLine : string.Empty) + "StackTrace:" + Environment.NewLine + eException.StackTrace); } }
private void button3_Click(object sender, EventArgs e) { //remove contact int index = dataGridView1.CurrentRow.Index; TestServiceClient client = new TestServiceClient(); try { int number = Convert.ToInt32(dataGridView1.Rows[index].Cells[1].Value.ToString()); client.Open(); client.DeleteContact(number); client.Close(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void Window_Closed(object sender, EventArgs e) { string dirpatch = ""; if (!ApplicationDeployment.IsNetworkDeployed) { //строка для отладки dirpatch = "CHG_maker_log.txt"; //dirpatch = @"C:\Users\Roman\Desktop\OFP" + "\\CHG_maker_log.txt"; } else { //строка для продакшена dirpatch = ApplicationDeployment.CurrentDeployment.DataDirectory.ToString() + "\\CHG_maker_log.txt"; } try { //((App)Application.Current).OFPLIST string dateTImeNow = String.Format("{0:MM.dd.yyyy HH:mm:ss}", DateTime.Now); string username = Environment.UserName; string userdomain = Environment.UserDomainName; string useremail = adGetInfo(username, userdomain); // //Statistic_ServiceClient service_proxy = new Statistic_ServiceClient(); TestServiceClient somee_proxy = new TestServiceClient(); StreamWriter sw = File.AppendText(dirpatch); foreach (OFP tempOfp in ((App)Application.Current).OFPLIST) { sw.WriteLine(tempOfp.Flight + " " + dateTImeNow + " " + useremail); //service_proxy.AddLogAsync(tempOfp.Flight + " " + dateTImeNow + " " + useremail); somee_proxy.addCHGAsync(dateTImeNow + " " + tempOfp.Flight + " " + useremail); } somee_proxy.Close(); //service_proxy.Close(); } catch (Exception ex) { MessageBox.Show("Could not read file. Error message: " + ex.Message); } }
private void button2_Click(object sender, EventArgs e) { //add contact Form2 form2 = new Form2(); form2.ShowDialog(); ContactData data = form2.ReturnData(); TestServiceClient client = new TestServiceClient(); try { client.Open(); client.PushContact(data.name, data.number); client.Close(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); return; } }
private void InvokeService(int delay) { this.Trace.Write(string.Format("Calling service on thread {0}", Thread.CurrentThread.ManagedThreadId)); var proxy = new TestServiceClient(); try { var result = proxy.DoWork(delay); proxy.Close(); this.Trace.Write(string.Format("Completed calling service on thread {0} delay {1}", Thread.CurrentThread.ManagedThreadId, result)); this.labelDelay.Text = result.ToString(); } catch (Exception) { proxy.Abort(); throw; } }
private void button4_Click(object sender, EventArgs e) { //modify contact int index = dataGridView1.CurrentRow.Index; try { string name = dataGridView1.Rows[index].Cells[0].Value.ToString(); int number = Convert.ToInt32(dataGridView1.Rows[index].Cells[1].Value.ToString()); Form2 form2 = new Form2(new ContactData(name, number)); form2.ShowDialog(); ContactData data = new ContactData(); data = form2.ReturnData(); TestServiceClient client = new TestServiceClient(); client.Open(); client.ModifyContact(number, data.number); client.Close(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void button6_Click(object sender, EventArgs e) { dataGridView1.Rows.Clear(); Form2 form2 = new Form2(2); form2.ShowDialog(); ContactData data = form2.ReturnData(); TestServiceClient client = new TestServiceClient(); try { client.Open(); int[] phones = client.SearchPhone(data.name); client.Close(); int count = phones.Count(); if (count != 0) for (int i = 0; i < count; i++) dataGridView1.Rows.Add(data.name, phones[i].ToString()); else { foreach (Control c in Controls) c.Enabled = false; button1.Enabled = true; } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void button5_Click(object sender, EventArgs e) { //search name dataGridView1.Rows.Clear(); Form2 form2 = new Form2(1); form2.ShowDialog(); ContactData data = form2.ReturnData(); TestServiceClient client = new TestServiceClient(); try { client.Open(); string name = client.SearchName(data.number); client.Close(); if (name != null) dataGridView1.Rows.Add(name, data.number.ToString()); else { foreach (Control c in Controls) c.Enabled = false; button1.Enabled = true; } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }