コード例 #1
0
        private void RegisterGrpcServices(IServiceCollection services)
        {
            var cartChannel = new Channel(Configuration["RpcClients:CartService"], ChannelCredentials.Insecure);
            var cartClient  = new CartServiceClient(cartChannel);

            var inventoryChannel = new Channel(Configuration["RpcClients:InventoryService"],
                                               ChannelCredentials.Insecure);
            var inventoryClient = new InventoryServiceClient(inventoryChannel);

            var reviewChannel = new Channel(Configuration["RpcClients:ReviewService"], ChannelCredentials.Insecure);
            var reviewClient  = new ReviewServiceClient(reviewChannel);
            var pingClient    = new PingServiceClient(reviewChannel);

            var catalogChannel =
                new Channel(Configuration["RpcClients:CatalogService"], ChannelCredentials.Insecure);
            var catalogClient = new CatalogServiceClient(catalogChannel);

            var ratingChannel = new Channel(Configuration["RpcClients:RatingService"], ChannelCredentials.Insecure);
            var ratingClient  = new RatingServiceClient(ratingChannel);

            services.AddSingleton(typeof(CartServiceClient), cartClient);
            services.AddSingleton(typeof(InventoryServiceClient), inventoryClient);
            services.AddSingleton(typeof(ReviewServiceClient), reviewClient);
            services.AddSingleton(typeof(PingServiceClient), pingClient);
            services.AddSingleton(typeof(CatalogServiceClient), catalogClient);
            services.AddSingleton(typeof(RatingServiceClient), ratingClient);
        }
コード例 #2
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddStandardTemplate((svc, resolver) =>
            {
                var config = resolver.GetService <IConfiguration>();

                var cartChannel = new Channel(config["RpcClients:CartService"], ChannelCredentials.Insecure);
                var cartClient  = new CartServiceClient(cartChannel);

                var inventoryChannel = new Channel(config["RpcClients:InventoryService"], ChannelCredentials.Insecure);
                var inventoryClient  = new InventoryServiceClient(inventoryChannel);

                var reviewChannel = new Channel(config["RpcClients:ReviewService"], ChannelCredentials.Insecure);
                var reviewClient  = new ReviewServiceClient(reviewChannel);
                var pingClient    = new PingServiceClient(reviewChannel);

                var catalogChannel = new Channel(config["RpcClients:CatalogService"], ChannelCredentials.Insecure);
                var catalogClient  = new CatalogServiceClient(catalogChannel);

                var ratingChannel = new Channel(config["RpcClients:RatingService"], ChannelCredentials.Insecure);
                var ratingClient  = new RatingServiceClient(ratingChannel);

                services.AddSingleton(typeof(CartServiceClient), cartClient);
                services.AddSingleton(typeof(InventoryServiceClient), inventoryClient);
                services.AddSingleton(typeof(ReviewServiceClient), reviewClient);
                services.AddSingleton(typeof(PingServiceClient), pingClient);
                services.AddSingleton(typeof(CatalogServiceClient), catalogClient);
                services.AddSingleton(typeof(RatingServiceClient), ratingClient);
            });
        }
コード例 #3
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.Out.WriteLine("\nUsage: caawsping <appserver_root_uri>");
                Environment.Exit(0);
            }
            try {
                // A few proverbs for tests.
                string[] testData = { "Calling the PING web service in a CAA context",
                                      "He that will steal a penny will steal a pound.",
                                      "When the cat is away, the mice will play",
                                      "The early bird catches the worm." };
                int[]    wordCounts = { 9, 10, 9, 6 };

                // Compute the service address based on the supplied application
                // server root URI
                string serviceAddress = args[0] + "/webservice?id=ping";

                // Create an instance of ping proxy. One needs to specify:
                // - the name of the binding (it must match the binding name defined
                // in App.config).
                // - the address of the service
                PingServiceClient pingProxy = new PingServiceClient("IPingServiceBinding", serviceAddress);

                // Call the Ping web service four times.
                // The Web Service output is the word count of the input string...
                Console.WriteLine("Ping {0}", serviceAddress);


                for (int i = 0; i < 4; i++)
                {
                    System.Nullable <int> count = pingProxy.ping(testData[i]);
                    if (count != wordCounts[i])
                    {
                        Console.WriteLine("An error has occurred, count={0} and should be {1}", count, wordCounts[i]);
                    }
                    else
                    {
                        Console.Write(" input={0} ---> words count={1}", testData[i], count);
                        Console.WriteLine(" OK");
                    }
                }
            } catch (FaultException <ErrorType> error) {
                // Handle application level errors.
                Console.WriteLine("Error {0} has occurred: {1}", error.Detail.id, error.Detail.message);
                Environment.Exit(1);
            } catch (Exception e) {
                // Handle other errors.
                Console.WriteLine(e.ToString());
                Environment.Exit(1);
            }
        }
コード例 #4
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddStandardTemplate((svc, resolver) =>
            {
                var cartChannel = new Channel(Configuration["RpcClients:CartService"], ChannelCredentials.Insecure);
                var cartClient  = new CartServiceClient(cartChannel);

                var inventoryChannel = new Channel(Configuration["RpcClients:InventoryService"],
                                                   ChannelCredentials.Insecure);
                var inventoryClient = new InventoryServiceClient(inventoryChannel);

                var reviewChannel = new Channel(Configuration["RpcClients:ReviewService"], ChannelCredentials.Insecure);
                var reviewClient  = new ReviewServiceClient(reviewChannel);
                var pingClient    = new PingServiceClient(reviewChannel);

                var catalogChannel =
                    new Channel(Configuration["RpcClients:CatalogService"], ChannelCredentials.Insecure);
                var catalogClient = new CatalogServiceClient(catalogChannel);

                var ratingChannel = new Channel(Configuration["RpcClients:RatingService"], ChannelCredentials.Insecure);
                var ratingClient  = new RatingServiceClient(ratingChannel);

                services.AddSingleton(typeof(CartServiceClient), cartClient);
                services.AddSingleton(typeof(InventoryServiceClient), inventoryClient);
                services.AddSingleton(typeof(ReviewServiceClient), reviewClient);
                services.AddSingleton(typeof(PingServiceClient), pingClient);
                services.AddSingleton(typeof(CatalogServiceClient), catalogClient);
                services.AddSingleton(typeof(RatingServiceClient), ratingClient);

                services.AddSingleton <ICoolStoreResolverService, CoolStoreResolverService>();
                services.AddSingleton <CoolStoreSchema>();
                services.AddSingleton(provider => provider.GetRequiredService <CoolStoreSchema>().CoolStore);

                services.AddSignalR(options => options.EnableDetailedErrors = true)
                .AddQueryStreamHubWithTracing();

                services.AddCors(options =>
                {
                    options.AddDefaultPolicy(policy =>
                    {
                        policy.WithOrigins("*");
                        policy.AllowAnyHeader();
                        policy.AllowAnyMethod();
                        policy.AllowCredentials();
                        policy.WithHeaders("X-Requested-With", "authorization");
                    });
                });

                services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            });
        }
コード例 #5
0
    /**
     * CallService
     * Parms were already read. Now call the service proxy classes
     *
     */
    void CallService()
    {
        // Instantiate the service, and create the service url
        PingServiceClient pingsv;

        if (url.Length == 0)
        {
            // case : when the configuration is generated from the uri ( web service deployed in WCF and secured);
            Console.WriteLine("CLIENT>> creates the client proxy : use Ping endpoint from config file.");
            Console.WriteLine();
            pingsv = new PingServiceClient();
        }
        else
        {
            // Else ( Web service deployed on was, or proxy generated from a static wsdl file).
            Console.WriteLine("CLIENT>> creates the client proxy : use input url.");
            Console.WriteLine();
            // the first parameter must equals the "name" attributevalue of the <endpoint> tag in the config file.
            // here, it's the name you find in the "TestCAASecuredWSPing.exe.was.config" file.
            // Adapt the value, according to the name found in the associated config file.
            // the second parameter is the url...

            pingsv = new PingServiceClient("IPingServiceBinding_IPingService", url);
        }



        try
        {
            Console.WriteLine("CLIENT>> call the ping method.\n");
            System.Nullable <int> count = pingsv.ping(msg);

            string[] words = msg.Split(null);
            int      wc    = words.Length;
            if (count != wc)
            {
                Console.WriteLine("CLIENT>> An error has occurred, count={0} and should be {1}", count, wc);
            }
            else
            {
                Console.WriteLine("CLIENT>>   input ping request = \"{0}\" ", msg);
                Console.WriteLine("CLIENT>> words count response =  {0} ", count);
                Console.WriteLine("CLIENT>> ===> OK");
            }
        }

        catch (Exception e)
        {
            Console.WriteLine(">>>PING SERVICE EXCEPTION<<<\n" + e);
        }
    }
コード例 #6
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddStandardTemplate((svc, resolver) =>
            {
                var cartChannel = new Channel(Configuration["RpcClients:CartService"], ChannelCredentials.Insecure);
                var cartClient  = new CartServiceClient(cartChannel);

                var inventoryChannel = new Channel(Configuration["RpcClients:InventoryService"],
                                                   ChannelCredentials.Insecure);
                var inventoryClient = new InventoryServiceClient(inventoryChannel);

                var reviewChannel = new Channel(Configuration["RpcClients:ReviewService"], ChannelCredentials.Insecure);
                var reviewClient  = new ReviewServiceClient(reviewChannel);
                var pingClient    = new PingServiceClient(reviewChannel);

                var catalogChannel =
                    new Channel(Configuration["RpcClients:CatalogService"], ChannelCredentials.Insecure);
                var catalogClient = new CatalogServiceClient(catalogChannel);

                var ratingChannel = new Channel(Configuration["RpcClients:RatingService"], ChannelCredentials.Insecure);
                var ratingClient  = new RatingServiceClient(ratingChannel);

                services.AddSingleton(typeof(CartServiceClient), cartClient);
                services.AddSingleton(typeof(InventoryServiceClient), inventoryClient);
                services.AddSingleton(typeof(ReviewServiceClient), reviewClient);
                services.AddSingleton(typeof(PingServiceClient), pingClient);
                services.AddSingleton(typeof(CatalogServiceClient), catalogClient);
                services.AddSingleton(typeof(RatingServiceClient), ratingClient);

                services.AddSingleton <ICoolStoreResolverService, CoolStoreResolverService>();
                services.AddSingleton <CoolStoreSchema>();
                services.AddSingleton(provider => provider.GetRequiredService <CoolStoreSchema>().CoolStore);

                services.AddCors(options =>
                {
                    options.AddPolicy("CorsPolicy",
                                      policy => policy
                                      .AllowAnyMethod()
                                      .AllowAnyHeader()
                                      /* https://github.com/aspnet/AspNetCore/issues/4457 */
                                      .SetIsOriginAllowed(host => true)
                                      .AllowCredentials());
                });

                services.AddSignalR(options => options.EnableDetailedErrors = true)
                .AddQueryStreamHubWithTracing();

                services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            });
        }
コード例 #7
0
 public ReviewController(ReviewServiceClient reviewServiceClient, PingServiceClient pingServiceClient)
 {
     _reviewServiceClient = reviewServiceClient;
     _pingServiceClient   = pingServiceClient;
 }