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); } }
public BindingList <TestForGrid> LoadTestsToCheckBox(BindingList <TestForGrid> testsFromGrid) { var dtoTest = new DtoTest1() { Code = string.Empty, Name = string.Empty }; var tests = new TestServiceClient().FindTests(dtoTest); var query = from testForCheckBox in testsFromGrid join test in tests on testForCheckBox.Code equals test.Code select new TestForGrid() { Code = test.Code, Name = test.Name, ConcreteCode = testForCheckBox.ConcreteCode }; var testsForCheckBox = new BindingList <TestForGrid>(); foreach (var testForGrid in query) { testsForCheckBox.Add(testForGrid); } return(testsForCheckBox); }
/// <summary> /// Main Method /// Main method for the program /// </summary> /// <param name="args">none used</param> static void Main(string[] args) { Console.WriteLine("Multithread Test to Service..."); Console.WriteLine(new string('=', 50)); Console.WriteLine($"There are {numThreads} threads that will run."); Console.WriteLine("Press <ENTER> to begin test..."); Console.ReadLine(); proxy = new TestServiceClient(); // Create and Run 5 threads in Parallel ParallelLoopResult result = Parallel.For(0, numThreads, x => { // Zero Based, Need to Make it start at 1 ServiceThread(x + 1); } ); // Make the main UI Wait until the threads are complete while (!IsComplete) { if (threadTimes?.Count == numThreads) { IsComplete = true; } } Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("COMPLETE"); Console.WriteLine("Press <ENTER> to run statistics..."); Console.ReadLine(); PrintStatistics(); Console.WriteLine("Press <ENTER> to quit..."); Console.ReadLine(); } // end of main method
private static void SubmitRequests(object data) { ManualResetEvent done = data as ManualResetEvent; Assert.IsNotNull(done); try { // Wait for channel to start receiving requests. The HttpListener should have started accepting // requests at this point but on a few occasions there seems to be a delay causing the HttpClient // requests that we start below to fail. By inserting this sleep we should be able to rule out // some lower level race condition. Thread.Sleep(BasicChannelTests.waitTimeout); using (var client = TestServiceClient.CreateClient()) { var result = TestServiceClient.RunClient(client, TestHeaderOptions.InsertRequest | TestHeaderOptions.ValidateResponse); int cnt = 0; foreach (var response in result) { cnt++; Assert.AreEqual(HttpStatusCode.OK, response.StatusCode, string.Format("Check failed in response {0}", cnt)); Assert.AreEqual(BasicChannelTests.ChannelHttpReasonPhrase, response.ReasonPhrase, string.Format("Check failed in response {0}", cnt)); } } } finally { done.Set(); } }
private Contract GetContractById(string contractId) { // Get the access token var accessToken = OpenIdConnectHelpers.GetSessionAccessToken(Request); if (accessToken == null) { return(null); } // Add the access token to the servicecall's request headers. // This example is taken from: http://stackoverflow.com/questions/964433/how-to-add-a-custom-http-header-to-every-wcf-call // The post describes a better implementation but this one shall do for the prototype. var client = new TestServiceClient(); Contract contract = null; // Open a OperationContextScope so we can edit the service calls http headers using (var scope = new OperationContextScope(client.InnerChannel)) { var httpRequestProperty = new HttpRequestMessageProperty(); httpRequestProperty.Headers[HttpRequestHeader.Authorization] = accessToken; OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpRequestProperty; try { var rpt = GetRequestingPartyToken(accessToken); contract = client.GetContract(contractId, rpt); } catch (FaultException <ServiceFault> fault) { } } return(contract); }
private void ComplexTest(string bindingName) { var compositeType = new CompositeType() { BoolValue = true, StringValue = "Test" }; try { using (var client = new TestServiceClient(bindingName)) { compositeType = client.GetDataUsingDataContract(compositeType); } } catch (Exception ex) { using (var client = new TestServiceClient(bindingName)) { compositeType = client.GetDataUsingDataContract(compositeType); } } AssertComposite(compositeType); }
private void btnCallAzureWCFTestService_Click(object sender, EventArgs e) { TestServiceClient testService = new TestServiceClient(); MessageBox.Show(testService.SayHello()); }
public override Task StartAsync(CancellationToken cancellationToken) { string env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); if (string.IsNullOrWhiteSpace(env)) { env = "Development"; } var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) .AddJsonFile($"appsettings.{env}.json", optional: true, reloadOnChange: true) .AddEnvironmentVariables(); IConfigurationRoot configuration = builder.Build(); var services = new ServiceCollection(); services.AddTransient <EmployeeClientDemo>(); services.RegisterEmployeeService(configuration); var provider = services.BuildServiceProvider(); client = new HttpClient(); wcfClient = new TestServiceClient(); wcfEmployeeClient = provider.GetService <EmployeeClientDemo>(); return(base.StartAsync(cancellationToken)); }
public void BasicCommTest() { string response; var start = Environment.TickCount; using (var client = new TestServiceClient("proto")) { var d = client.GetDataUsingDataContractAsync(new CompositeType() { BoolValue = true, StringValue = "Test" }); var composite = d.GetAwaiter().GetResult(); AssertComposite(composite); response = client.GetData(2); } var end = Environment.TickCount - start; Console.WriteLine(end); Assert.IsNotNull(response); Assert.IsTrue(response.Equals("2", StringComparison.Ordinal), "response was unexpected, expected : {0}, actual: {1}", "2", response); }
public void LongRunningTest() { using (var client = new TestServiceClient("proto")) { client.CallLongRunningService(); } }
private static void Main() { using (var testTcpClient = new TestServiceClient(Protocol.Tcp, IPAddress.Loopback)) { for (int i = 0; i < 10; i++) { var arg = new PingStruct { Value = i }; PingStruct result = testTcpClient.Ping_1(arg); Console.WriteLine($"PING1 TCP - Sent: {i}, Received: {result.Value}"); result = testTcpClient.Ping2_2(arg); Console.WriteLine($"PING2 TCP - Sent: {i}, Received: {result.Value}"); } } using var testUdpClient = new TestServiceClient(Protocol.Udp, IPAddress.Loopback); for (int i = 0; i < 10; i++) { var arg = new PingStruct { Value = i }; PingStruct result = testUdpClient.Ping_1(arg); Console.WriteLine($"PING1 UDP - Sent: {i}, Received: {result.Value}"); result = testUdpClient.Ping2_2(arg); Console.WriteLine($"PING2 UDP - Sent: {i}, Received: {result.Value}"); } }
// GET api/values/5 public string Get(int id) { using (var client = new TestServiceClient()) { return(client.GetData(id)); } }
private async void TestLargeSizeMessageButton_OnClick(object sender, RoutedEventArgs e) { InfoLabel.Text = "Running..."; _testServiceClient = new TestServiceClient(_serverAddress, _port); bool clientConnected = await _testServiceClient.StartConnection(); const int length = 30000; var charArray = new char[length]; charArray[0] = 'a'; for (int i = 1; i < length - 1; ++i) { charArray[i] = 'b'; } charArray[length - 1] = 'c'; var testString = new string(charArray); var response = (await _testServiceClient.SendMessage(testString)) as TestServiceResponse; if (response != null && response.Message.Equals(TestServiceConstants.ServicePrefix + testString)) { InfoLabel.Text = "Pass"; } else { InfoLabel.Text = "Fail"; } _testServiceClient.StopClient(); }
public async Task TestClientReConnect() { _testService = new TestServer(_port); Assert.AreEqual(true, _testService.StartService()); // first connection _testServiceClient = new TestServiceClient(_serverAddress, _port); bool clientConnected = await _testServiceClient.StartConnection(); Assert.AreEqual(true, clientConnected); const string testString = "Hello world!"; var response = (await _testServiceClient.SendMessage(testString)) as TestServiceResponse; Assert.IsNotNull(response); Assert.AreEqual(TestServiceConstants.ServicePrefix + testString, response.Message); _testServiceClient.StopClient(); // second connection clientConnected = await _testServiceClient.StartConnection(); Assert.AreEqual(true, clientConnected); response = (await _testServiceClient.SendMessage(testString)) as TestServiceResponse; Assert.IsNotNull(response); Assert.AreEqual(TestServiceConstants.ServicePrefix + testString, response.Message); _testServiceClient.StopClient(); _testService.StopService(); }
private async void TestMultiClientButton_OnClick(object sender, RoutedEventArgs e) { InfoLabel.Text = "Running..."; const int numClients = 5; TestServiceClient[] clients = new TestServiceClient[numClients]; for (int i = 0; i < numClients; ++i) { clients[i] = new TestServiceClient(_serverAddress, _port); bool clientConnected = await clients[i].StartConnection(); if (!clientConnected) { InfoLabel.Text = "Fail"; return; } } for (int i = 0; i < numClients; ++i) { bool success = await SendAndReceive(clients[i], i); if (!success) { InfoLabel.Text = "Fail"; return; } } for (int i = 0; i < numClients; ++i) { clients[i].StopClient(); } InfoLabel.Text = "Pass"; }
private async Task <bool> SendAndReceive(TestServiceClient client, int i) { string testString = i.ToString(); var response = (await client.SendMessage(testString)) as TestServiceResponse; return(response != null && response.Message.Equals(TestServiceConstants.ServicePrefix + testString)); }
public async Task TestMultipleClients() { _testService = new TestServer(_port); Assert.AreEqual(true, _testService.StartService()); const int numClients = 5; TestServiceClient[] clients = new TestServiceClient[numClients]; for (int i = 0; i < numClients; ++i) { clients[i] = new TestServiceClient(_serverAddress, _port); bool clientConnected = await clients[i].StartConnection(); Assert.AreEqual(true, clientConnected); } for (int i = 0; i < numClients; ++i) { await SendAndReceive(clients[i], i); } for (int i = 0; i < numClients; ++i) { clients[i].StopClient(); } _testService.StopService(); }
private static async Task DoWcfCallAsync(Func <TestServiceClient, Task> action) { using (TestServiceClient client = new TestServiceClient("NetTcpBinding_ITestService")) { await action(client); } }
static void Main(string[] args) { Service1Client c = new Service1Client(); c.GetData(5); var w = new CompositeType() { StringValue = "Moises" }; //c.GetDataUsingDataContract(w); TestServiceClient cc = new TestServiceClient(); cc.Greeting(); var uri = new Uri("http://www.google.com"); var request = WebRequest.Create(uri) as HttpWebRequest; var response = request.GetResponse() as HttpWebResponse; if (response.StatusCode == HttpStatusCode.OK) { using (var s = new StreamReader(response.GetResponseStream())) { Console.WriteLine(s.ReadToEnd()); } } else { Console.WriteLine(response.StatusCode); } Console.ReadKey(); }
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; }
private static void DoWcfCall(Action <TestServiceClient> action) { using (TestServiceClient client = new TestServiceClient("NetTcpBinding_ITestService")) { action(client); } }
public async Task TestLargeSizeMessage() { _testService = new TestServer(_port); Assert.AreEqual(true, _testService.StartService()); _testServiceClient = new TestServiceClient(_serverAddress, _port); bool clientConnected = await _testServiceClient.StartConnection(); Assert.AreEqual(true, clientConnected); const int length = 100000; var charArray = new char[length]; charArray[0] = 'a'; for (int i = 1; i < length - 1; ++i) { charArray[i] = 'b'; } charArray[length - 1] = 'c'; var testString = new string(charArray); // how to set a timeout? var response = (await _testServiceClient.SendMessage(testString)) as TestServiceResponse; Assert.IsNotNull(response); Assert.AreEqual(TestServiceConstants.ServicePrefix + testString, response.Message); _testServiceClient.StopClient(); // assert client is stopped? _testService.StopService(); }
static void Main(string[] args) { TestServiceClient aProxyClient = new TestServiceClient("NetNamedPipeBinding_ITestService"); var message = aProxyClient.EchoOperation("Hello wcf"); Console.WriteLine(message); Console.Read(); }
public void OpenChannel_Successful() { var target = new TestServiceClient(); target.OpenChannelTest(); target.HasOpenChannelTest.Should().BeTrue(); }
private void btnDiv_Click(object sender, EventArgs e) { var client = new TestServiceClient(); var answer = client.geteilt(double.Parse(txbWert1.Text), double.Parse(txbWert2.Text)); lblOutput.Text = "Output: " + answer; }
public static TestServiceClient GetTestService() { TestServiceClient client = new TestServiceClient(); client.Endpoint.Address = new EndpointAddress(ServerUrl + "WebServices/TestService.svc"); return(client); }
private async Task SendAndReceive(TestServiceClient client, int i) { string testString = i.ToString(); var response = (await client.SendMessage(testString)) as TestServiceResponse; Assert.IsNotNull(response); Assert.AreEqual(TestServiceConstants.ServicePrefix + testString, response.Message); }
static void Main(string[] args) { using (var client = new TestServiceClient()) { Console.WriteLine(client.GetMyName()); } Console.ReadKey(); }
public static void Main(string[] args) { TestServiceClient objClient = new TestServiceClient(); Console.WriteLine(objClient.DoWork()); Console.Read(); }
//[ExpectedException] public void TestLocalServiceMethod() { TestServiceClient objService = new TestServiceClient("WSHttpBinding_ITestService"); string str = objService.DoWork(); //ArithmaticOperations obj = new ArithmaticOperations(); //int i = obj.Divide(2, 1); Console.WriteLine("TestLocalServiceMethod output :" + str); }
public void DictionaryListComplexGetProto() { using (var client = new TestServiceClient("proto")) { var dictionary = client.GetDictionaryListComplex(); Assert.IsNotNull(dictionary); } }
public void DictionarySimpleGetProto() { using (var client = new TestServiceClient("proto")) { var dictionary = client.GetDictionarySimple(); Assert.IsNotNull(dictionary); } }
public void ListGetProto() { using (var client = new TestServiceClient("proto")) { var list = client.GetList(); Assert.IsNotNull(list); } }
static void Main(string[] args) { TestServiceClient client = new TestServiceClient(); client.Open(); int number = 12345600; Console.WriteLine(client.SearchName(number)); Console.ReadLine(); client.Close(); }
static void Main() { TestServiceClient client = new TestServiceClient(); var input = new Input() { X = 5, Y = 3 }; var result = client.Sum(input); Console.WriteLine(result); }
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 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 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 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()); } }
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 PrimitiveGet(string bindingName) { string response; using (var client = new TestServiceClient(bindingName)) { response = client.GetData(2); } Assert.IsNotNull(response); Assert.IsTrue(response.Equals("2", StringComparison.Ordinal), "response was unexpected, expected : {0}, actual: {1}", "2", response); }
private void BigComplexTest(string bindingName) { BigContract bigContract; using (var client = new TestServiceClient(bindingName)) { //client.InnerChannel.OperationTimeout = TimeSpan.FromSeconds(5); bigContract = client.GetDataUsingBigDataContract(BigContract); } Assert.IsNotNull(bigContract); Assert.IsNotNull(bigContract.CompositeTypes); foreach (var compositeType in bigContract.CompositeTypes) { AssertComposite(compositeType); } }
public void DictionaryMixedGetProtoTcp() { using (var client = new TestServiceClient("protoTcp")) { var dictionary = client.GetDictionaryMixed(); Assert.IsNotNull(dictionary); } }
public string LoadDefaultEntities(string code, BindingList<TestForGrid> testGrids, BindingList<SpecimenForGrid> specimenGrids, BindingList<TubeForGrid> tubeGrids) { if (testGrids.Count<TestForGrid>(test => test.Code == code) < 2) { var test = new TestServiceClient().GetTestByCode(code); var specimenForGrid = new SpecimenForGrid() { Code = test.DefaultSpecimen.Code }; specimenGrids.Add(specimenForGrid); LoadDefaultTube(test.DefaultSpecimen.Code, tubeGrids); return string.Empty; } else { return "Test is exist already!"; } }
public BindingList<TestForGrid> LoadTestsToCheckBox(BindingList<TestForGrid> testsFromGrid) { var dtoTest = new DtoTest1() { Code = string.Empty, Name = string.Empty }; var tests = new TestServiceClient().FindTests(dtoTest); var query = from testForCheckBox in testsFromGrid join test in tests on testForCheckBox.Code equals test.Code select new TestForGrid() { Code = test.Code, Name = test.Name, ConcreteCode =testForCheckBox.ConcreteCode }; var testsForCheckBox = new BindingList<TestForGrid>(); foreach (var testForGrid in query) { testsForCheckBox.Add(testForGrid); } return testsForCheckBox; }