public ActionResult Hello() { string result = "*No Response*"; string endpointName = null; try { endpointName = GlobalCache.GetResolvedString("EchoServiceEndpoint"); if (endpointName == null) { throw new ApplicationException("Could not find 'EchoServiceEndpoint' in configuration settings."); } Debug.WriteLine(string.Format("EchoServiceEndpoint='{0}'", endpointName)); // --------------------------------------------------------- // // --------------------------------------------------------- using (EchoServiceClient proxy = new EchoServiceClient(endpointName)) { result = proxy.Ping(); } } catch (Exception exp) { Request.PostError(exp); } return(View("Hello", (object)$"Endpoint: {endpointName ?? "*Unknown*"}, Result: {result}")); }
private void btnCallHttpDual_Click(object sender, EventArgs e) { try { System.ServiceModel.InstanceContext site = new System.ServiceModel.InstanceContext(new EchoServiceCallbackHandler()); asyncClient = new EchoServiceClient(site, "dualHttpEndPoint"); this.txtStatus.Text += String.Format("Connected...{0}\r\n", asyncClient.Endpoint.Address.Uri.AbsoluteUri); // invoke service operation this.txtStatus.Text += String.Format("Invoking Duplex endpoint: AsyncEchoJob1\r\n"); asyncClient.EchoJobStart("AsyncEchoJob1"); } catch (TimeoutException timeProblem) { this.txtStatus.Text += String.Format("The service operation timed out....{0}\r\n", timeProblem.Message); asyncClient.Abort(); } catch (System.ServiceModel.CommunicationException commProblem) { this.txtStatus.Text += String.Format("There was a communication problem....{0}\r\n", commProblem.Message); asyncClient.Abort(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { this.txtStatus.Text += String.Format("--------------------------------------\r\n"); } }
static void Main(string[] args) { //EchoServiceClient ist in WSDL beschrieben EchoServiceClient client = new EchoServiceClient(); var result = client.Echo("Hello World"); Console.WriteLine(result); Console.ReadLine(); }
public static void Main(string[] args) { var echoServiceClient = new EchoServiceClient("NetTcpBinding_IEchoService"); Console.WriteLine("Type to echo: "); while (true) { var message = Console.ReadLine(); var response = echoServiceClient.Echo(message); Console.WriteLine(response); } }
static async Task CreateAndCallClient() { using (var echoClient = new EchoServiceClient("EchoService")) { echoClient.ClientCredentials.UserName.UserName = @"username"; echoClient.ClientCredentials.UserName.Password = @"password"; // Don't validate certificates since they're just for test purposes echoClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None; echoClient.Open(); Console.WriteLine(await echoClient.SendStringAsync("Test12345")); } }
public static void Main(string[] args) { EchoServiceClient echoClient = new EchoServiceClient(); Console.WriteLine("Echo(\"Is anyone there?\") returned: " + echoClient.Echo("Is anyone there?")); echoClient.Close(); CalculatorServiceClient calculatorClient = new CalculatorServiceClient(); Console.WriteLine("Add(5) returned: " + calculatorClient.Add(5)); Console.WriteLine("Add(-3) returned: " + calculatorClient.Add(-3)); calculatorClient.Close(); Console.WriteLine(); Console.WriteLine("Press Enter to exit..."); Console.ReadLine(); }
private static async Task CreateAndCallClient() { // Cache the WCF client so that its ChannelFactory is reused. // This sort of caching (reusing channel factory) happens automatically // in NetFx when using config-based clients. In NetCore, though, users // will need to manage this themselves to keep good performance. if (EchoServiceClient == null) { EchoServiceClient = new EchoServiceClient(GetBinding(), Endpoint); EchoServiceClient.ClientCredentials.UserName.UserName = @"username"; EchoServiceClient.ClientCredentials.UserName.Password = @"password"; // Don't validate certificates since they're just for test purposes EchoServiceClient.ClientCredentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication() { CertificateValidationMode = X509CertificateValidationMode.None, RevocationMode = X509RevocationMode.NoCheck }; } Console.WriteLine(await EchoServiceClient.SendStringAsync("TestABCDEF")); }
void GetNow() { var client = new EchoServiceClient(); var r = client.GetNow(); _Logs.Add(r); }
void Echo() { var client = new EchoServiceClient(); var r = client.Echo(TextRequest.Text); _Logs.Add(r); }
private void CallService(string endpointConfName) { try { //System.Xml.XmlDocument dom = new System.Xml.XmlDocument(); //dom.Load(string.Concat(System.Reflection.Assembly.GetExecutingAssembly().Location, ".config")); //System.Xml.XmlNode node = dom.SelectSingleNode("configuration/system.serviceModel/host/baseAddresses"); if (client == null || endpointConfName != currentClientEndpointName) { client = new EchoServiceClient(site, endpointConfName); currentClientEndpointName = endpointConfName; } this.txtStatus.Text += String.Format("Connected...{0}\r\n", client.Endpoint.Address.Uri.AbsoluteUri); // invoke service operation this.txtStatus.Text += String.Format("Invoking endpoint: {0}\r\n", client.Echo("Duck Chang Park")); xdndcpark.WCF.person.Person oPerson = new xdndcpark.WCF.person.Person(); oPerson.first = "duck chang"; oPerson.last = "park"; oPerson = client.EchoPerson(oPerson); this.txtStatus.Text += String.Format("Invoking endpoint: {0}, {1}\r\n", oPerson.first, oPerson.last); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { this.txtStatus.Text += String.Format("--------------------------------------\r\n"); } }
public void Run() { try { using (EchoServiceClient proxy = new EchoServiceClient(_echoServiceEndpointName)) { string result = ""; result = proxy.Ping(); Console.WriteLine(string.Format("EchoService : {0}", result)); } } catch (System.ServiceModel.EndpointNotFoundException) { Trace.WriteLine(string.Format("!Note! : No endpoint listening at [{0}]", _echoServiceEndpointName)); } using (LibraryServiceClient proxy = new LibraryServiceClient(_libraryServiceEndpointName)) { Book book = null; Action prompt = new Action(() => { Console.WriteLine("LIST - Return a list of Books using the Search Pattern."); Console.WriteLine("READ - Return a Book using the Key value."); Console.WriteLine("Press ENTER to terminate."); }); prompt(); string input = ""; StringBuilder sb = new StringBuilder(); while ((input = Console.ReadLine().ToUpper()).Length > 0) { try { string[] tokens = input.Split(' '); switch ((tokens.Length) > 0 ? tokens[0] : "") { case "LIST": Console.Write("Search Pattern : "); string searchPattern = Console.ReadLine(); proxy.List(searchPattern, out books); Stream stream = new MemoryStream(); EntitySerializationHelpers.SerializeBooks(books.ToList(), stream); Console.WriteLine(stream.ContentsToString()); break; case "LOAD": Stream xstream = StreamFactory.Create(@"res://AppData.Books.xml"); Console.WriteLine(string.Format("Load = {0}", proxy.Load(xstream))); break; case "READ": Console.Write("Key : "); string key = Console.ReadLine(); if (proxy.Read(key, out book)) { stream = new MemoryStream(); EntitySerializationHelpers.SerializeBook(book, stream); Console.WriteLine(stream.ContentsToString()); } else { Console.WriteLine(" *Not Found*"); } break; default: prompt(); break; } } catch (Exception exp) { Trace.WriteLine(string.Format("Error {0} : {1}", input, exp.Message)); } } } }