Beispiel #1
0
        private static Lazy <ServiceProxy> LoadFromConfig(ClientConfig config)
        {
            ClientContext.CreateNew(config);

            if (_commandServiceProxy == null)
            {
                var lazyConnection = new Lazy <ServiceProxy>(() =>
                {
                    var contextConfig = ClientContext.Current.Config;
                    var client        =
                        WcfClient <ICommandService <object> > .Create(contextConfig.Runtime.Client.GetWcfServiceType(),
                                                                      contextConfig.Runtime.Client.Host,
                                                                      contextConfig.Runtime.Client.Port.ToString(CultureInfo.InvariantCulture),
                                                                      "CommandService");

                    client.OnFaulted += client_OnFaulted;
                    CurrentContext.Default.Log.Info("Connection Established:" + client.ServerName + " Port:" +
                                                    client.Port);

                    return(new ServiceProxy(client.Contract, config));
                });

                _commandServiceProxy = lazyConnection;
            }

            return(_commandServiceProxy);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            /*
             * call service using static methods
             */
            // call service method with return value
            var currentTime = WcfClient.RequestService <IWcfExampleService, DateTime>(service => service.GetCurrentDateTime());

            Console.WriteLine("Current Time: {0}", currentTime);

            // call service method without return value
            WcfClient.RequestService <IWcfExampleService>(service => service.SayHello("Hello wcf!"));

            /*
             * call service using WcfClient object
             */

            //var client = new WcfClient<IWcfExampleService>(new ProxyBuilder("WcfExampleService"));
            var client = WcfClient.Create <IWcfExampleService>();

            // call service method with return value
            currentTime = client.RequestService <DateTime>(service => service.GetCurrentDateTime());
            Console.WriteLine("Current Time: {0}", currentTime);

            // call service method without return value
            client.RequestService(service => service.SayHello("Hello again!"));

            Console.WriteLine("Press ENTER to exit...");
            Console.ReadLine();
        }
Beispiel #3
0
        private ServiceCommandOutput <object> CheckServiceConnectivity(string port, ServiceType type,
                                                                       ServiceSecurityMode mode)
        {
            var service = new WcfService <ICommandService <object>, DummyNativeCommandService>("localhost", ServiceName);

            service.AddBinding(BindingFactory.Create(new BindingConfiguration {
                Port = port, ServiceType = type
            }));
            if (mode == ServiceSecurityMode.BasicSSL)
            {
                var serviceSecurity = new ServiceSecurity
                {
                    SecurityMode             = ServiceSecurityMode.BasicSSL,
                    CertificateConfiguration = _certificateConfiguration
                };

                service.SetSecured(serviceSecurity);
            }

            service.Host();

            var client = WcfClient <ICommandService <object> > .Create(type, "localhost", port, ServiceName, "api", mode);

            var output = client.Contract.ExecuteCommand("test", "token");

            service.Stop();
            return(output);
        }