public static void Main(string[] args) { EchoService server = new EchoService(); string request = "Test C#"; server.Echo(ref request); Console.WriteLine("Return: " + request); }
public void Insert_Test() { EchoAddRequest model = new EchoAddRequest { Echo = "ECHO Echo echo" }; EchoService svc = new EchoService(); int result = svc.Insert(model); Assert.IsTrue(result > 0, "The insert failed!"); }
static void Main(string[] args) { //var binding = new BasicHttpBinding(); //var serviceUrl = "http://localhost:8502/Calculator.svc"; //var calculator = ServiceProxyFactory.CreatePorxy<Server.Service.ICalculator>(binding, serviceUrl); //for (int i = 0; i < 100; i++) //{ // //calculator.Add(12, 24); // //calculator.Subtract(36, 10); // //calculator.Multiply(12, 35); // //calculator.Divide(36, 12); //} ////calculator = ServiceProxyFactory.CreateCastleProxy<Server.Service.ICalculator>(binding, serviceUrl); ////for (int i = 0; i < 100; i++) ////{ //// calculator.Add(12, 24); //// calculator.Subtract(36, 10); //// calculator.Multiply(12, 35); //// calculator.Divide(36, 12); ////} //serviceUrl = "http://localhost:8502/Message.svc"; //var message = ServiceProxyFactory.CreatePorxy<Server.Service.IMessage>(binding, serviceUrl); ////message.Echo("小古"); ////var serviceProxy = new CalculatorServiceProxy(new CalculatorService()); ////var calculator = (ICalculator)serviceProxy.GetTransparentProxy(); ////calculator.Add(12, 24); ////calculator.Subtract(36, 10); ////calculator.Multiply(12, 35); ////calculator.Divide(36, 12); //Console.ReadKey(); var container = new WindsorContainer(); container.Register( Component.For <EchoService, IEchoService>(), Component.For(typeof(EchoInterceptor)).LifestyleTransient(), Component.For(typeof(EmptyClass)).Proxy.AdditionalInterfaces(typeof(IEchoService)) .Interceptors(typeof(EchoInterceptor)).LifestyleTransient() ); var emptyClass = new EchoService(); var methodInfo = emptyClass.GetType().GetMethod("Echo"); methodInfo.Invoke(emptyClass, new object[] { "Dynamic WebApi" }); Console.ReadKey(); }
public void EchoCall() { EchoService service = new EchoService(); JsonRpcDispatcher server = new JsonRpcDispatcher(service); service.NextResult = "Hello"; string responseString = server.Process("{ id : 1, method : 'Say', params : [ 'Hello' ] }"); IDictionary response = (IDictionary) Parse(responseString); Assert.AreEqual(1, response["id"]); Assert.IsFalse(response.Contains("error")); Assert.AreEqual("Say", service.LastMethodName); Assert.AreEqual(new object[] { "Hello" }, service.LastArguments); Assert.AreEqual("Hello", response["result"]); }
static void Main(string[] args) { ServiceHost[] svcHosts = null; try { EchoService.StartLoggerNoEmail(); svcHosts = new ServiceHost[] { new ServiceHost(typeof(Skywolf.MarketDataService.Restful.MarketDataRfService)) }; foreach (ServiceHost host in svcHosts) { host.Open(); Console.WriteLine("Serivce: {0} \t\t State:{1}", host.Description.Name, host.State); } // ModelBase.InitHolidaySchedule(); Console.WriteLine(); Console.WriteLine("Press <ENTER> to terminate Host"); Console.ReadLine(); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.ReadLine(); EchoService.Logger.Error(string.Format("Exception thrown from {0}", "unknown"), ex); } finally { if (svcHosts != null) { foreach (ServiceHost host in svcHosts) { if (host.State == CommunicationState.Faulted) { host.Abort(); } else { host.Close(); } } } //Prcm.Services.Models.ModelBase.UnInitHolidaySchedule(); //EchoService.DeleteLog(); } }
public static void Run() { { // The echo service often returns back the same item that it received. We should configure it to enable shared strings // and other optimizations. SerializerSettings settings = new() { // Memory copy serialization enables fast re-serialization for already-deserialized flatbuffer items. // Since the echo service is simple, this is a good optimization to enable. EnableMemoryCopySerialization = true, // Turn on writing shared strings. SharedStringWriterFactory = () => new SharedStringWriter(), }; // Update the serializers used for the echo service. EchoService.Serializer <SingleMessage> .Value = EchoService.Serializer <SingleMessage> .Value.WithSettings(settings); EchoService.Serializer <MultiMessage> .Value = EchoService.Serializer <MultiMessage> .Value.WithSettings(settings); } Server server = new Server(); server.Ports.Add("127.0.0.1", 50001, ServerCredentials.Insecure); server.Services.Add(EchoService.BindService(new ServerImpl())); server.Start(); Thread.Sleep(1000); EchoService.EchoServiceClient client = new(new Channel("127.0.0.1", 50001, ChannelCredentials.Insecure)); // We can use the client in two different ways: // 1) as a traditional gRPC client: GrpcOperations(client).GetAwaiter().GetResult(); // 2) As an async interface with Channel<T> InterfaceOperations((IEchoService)client).GetAwaiter().GetResult(); Thread.Sleep(1000); server.ShutdownAsync().GetAwaiter().GetResult(); }
private async Task EchoTest(Func <EchoService.EchoServiceClient, Task> callback) { Server server = new Server(); try { server.Services.Add(EchoService.BindService(new EchoServer())); server.Ports.Add(new ServerPort("127.0.0.1", 0, ServerCredentials.Insecure)); server.Start(); int port = server.Ports.Single().BoundPort; EchoService.EchoServiceClient client = new EchoService.EchoServiceClient(new Channel("127.0.0.1", port, ChannelCredentials.Insecure)); await callback(client); } finally { await server.KillAsync(); } }
public HttpResponseMessage Post([FromBody] EchoAddRequest model) { try { if (ModelState.IsValid) { EchoService svc = new EchoService(); ItemResponse <int> response = new ItemResponse <int>(); response.Item = svc.Insert(model); return(Request.CreateResponse(HttpStatusCode.OK, response)); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState)); } } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message)); } }
// Start the Windows service. protected override void OnStart(string[] args) { try { EchoService.StartLogger(); _log = EchoService.Logger; List <Type> serviceTypes = new List <Type>(); string path = Path.GetDirectoryName(Environment.GetCommandLineArgs()[0]); var files = Directory.GetFiles(path, "Skywolf.*Service.dll"); List <string> serviceBinaries = new List <string>(); files.ToList().ForEach(serviceBinaries.Add); TypeFilter myFilter = new TypeFilter((typeObj, criteriaObj) => typeObj.ToString() == criteriaObj.ToString()); foreach (string filePath in serviceBinaries) { _log.InfoFormat("Module: {0}", filePath); Assembly asm = Assembly.LoadFile(filePath); Type[] exportedTypes = asm.GetExportedTypes(); foreach (Type t in exportedTypes) { if (t.IsAbstract) { continue; } Type[] myInterfaces = t.FindInterfaces(myFilter, ECHO_INTERFACE); if (myInterfaces.Length > 0 && CustomServiceHost.Contains(t)) { serviceTypes.Add(t); } } } string hostMode = ConfigurationManager.AppSettings["HostMode"]; if (string.IsNullOrEmpty(hostMode)) { hostMode = "Multiple"; } if (string.Equals(hostMode, "Single", StringComparison.OrdinalIgnoreCase) && serviceTypes.Count > 1) { throw new ArgumentException("current design of service hose supports only one model."); } if (serviceTypes.Count() == 0) { throw new ArgumentException("no service is found."); } svcHosts = new CustomServiceHost[serviceTypes.Count]; int i = 0; var config = new XPathDocument(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile); var servicesElement = config.CreateNavigator().SelectSingleNode("//system.serviceModel/services"); var logOperationBehavior = new LogOperationBehavior(); foreach (Type serviceType in serviceTypes) { var host = new CustomServiceHost(serviceType); var firstEp = host.Description.Endpoints[0]; var binding = firstEp.Binding; foreach (var op in firstEp.Contract.Operations) { if (op.Name != "UpdateStatus") //filter out UpdateStatus. { op.Behaviors.Add(logOperationBehavior); } } host.AddServiceEndpoint(ECHO_INTERFACE, binding, "Echo"); Binding newBinding; var bindingConfig = servicesElement.SelectSingleNode( string.Format("service[@name='{0}']/endpoint[1]/@bindingConfiguration", host.Description.ConfigurationName)); if (binding is NetTcpBinding) { var newTcpBinding = new NetTcpBinding(bindingConfig.Value); newTcpBinding.Security.Mode = SecurityMode.Transport; newTcpBinding.Security.Transport.ProtectionLevel = System.Net.Security.ProtectionLevel.Sign; newBinding = newTcpBinding; } else if (binding is WebHttpBinding) { var newHttpBinding = new WebHttpBinding(bindingConfig.Value); newHttpBinding.Security.Mode = WebHttpSecurityMode.TransportCredentialOnly; newHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows; newBinding = newHttpBinding; } else { var newHttpBinding = new BasicHttpBinding(bindingConfig.Value); newHttpBinding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly; newHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows; newBinding = newHttpBinding; } host.AddServiceEndpoint(host.Description.Endpoints[0].Contract.ContractType, newBinding, "wid"); host.Open(); _log.Info(String.Format("{0} service is ready.", serviceType.Name)); foreach (var endpoint in host.Description.Endpoints) { _log.Info(String.Format("service endpoint: {0}", endpoint.Address)); } svcHosts[i] = host; i++; } } catch (Exception ex) { _log.Error(string.Format("Exception thrown from {0}", "unknown"), ex); throw; } }
static void Main(string[] args) { EchoService.StartLogger(); _log = EchoService.Logger; ConnectServiceTest(); }
public EchoCtlUnit(EchoService service) { _service = service; }
/** * CallService * Parms were already read. Now call the service proxy classes * */ void CallService() { if (SERVTYPE.ECHO == servtype) // Echo { if (0 == urlSuffix.Length) { urlSuffix = ECHO_CONTEXT; } EchoService echosv = new EchoService(); Console.WriteLine("CLIENT>> Connecting to Echo Service..."); echosv.Url = uriString + urlSuffix; Console.WriteLine("CLIENT>> Connected. Sending Echo Request to "+echosv.Url+"..."); try { echoStringInput echoParm = new echoStringInput(); echoParm.echoInput = msg; Console.WriteLine("CLIENT>> Sending message '"+ msg + "' ..."); echoStringResponse result = echosv.echoOperation(echoParm); Console.WriteLine("CLIENT>> The answer is '" + result.echoResponse + "'"); } catch (Exception e) { Console.WriteLine(">>>ECHO SERVICE EXCEPTION<<<\n" + e); } } else if (SERVTYPE.ASYNC == servtype) // Async Echo { if (0 == urlSuffix.Length) { urlSuffix = ECHO_CONTEXT; } // Instantiate the service, and create the service url EchoService echosv = new EchoService(); Console.WriteLine("CLIENT>> Connecting to Async Echo Service..."); echosv.Url = uriString + urlSuffix; Console.WriteLine("CLIENT>> Connected. Sending Echo Request to "+echosv.Url+"..."); try { // Create the argument object and IAsyncResult, then invoke Async echoStringInput echoParm = new echoStringInput(); echoParm.echoInput = msg; Console.WriteLine("CLIENT>> Sending Async message '" + msg + "' ..."); IAsyncResult ar = echosv.BeginechoOperation(echoParm, EchoCallback, echosv); int waiting = timeout; Thread.Sleep(1000); // Wait for completion while (!ar.IsCompleted) { if (waiting <= 0) { Console.WriteLine("CLIENT>> ERROR - Timeout waiting for reply."); break; } Console.WriteLine("CLIENT>> invocation still not complete"); Thread.Sleep(1000 * SLEEPER); waiting -= SLEEPER; } Console.WriteLine("CLIENT>> Async Invocation Complete"); } catch (Exception e) { Console.WriteLine(">>>ECHO SERVICE EXCEPTION<<<\n" + e); } } else // must be Ping { if (0 == urlSuffix.Length) { urlSuffix = PING_CONTEXT; } PingService pingsv = new PingService(); Console.WriteLine("CLIENT>> Connecting to Ping Service..."); pingsv.Url = uriString + urlSuffix; Console.WriteLine("CLIENT>> Connected. Sending Echo Request to "+pingsv.Url+"..."); try { pingStringInput pingParm = new pingStringInput(); pingParm.pingInput = msg; Console.WriteLine("CLIENT>> Sending message '"+ msg + "' ..."); pingsv.pingOperation(pingParm); Console.WriteLine("CLIENT>> Ping complete. Check server log to verify message delivery."); } catch (Exception e) { Console.WriteLine(">>>PING SERVICE EXCEPTION<<<\n" + e); } } }
public EchoBot(EchoService service) { _service = service; }