예제 #1
0
        public static ServiceConfiguration ApplyCustomAuthentication
            (this ServiceConfiguration config, Type serviceType, string address)
        {
            config.Credentials.IdentityConfiguration    = CreateIdentityConfiguration();
            config.Credentials.UseIdentityConfiguration = true;
            config.Description.Behaviors.Add(new ServiceMetadataBehavior {
                HttpGetEnabled = true
            });
            config.Description.Behaviors.Add(new ServiceDebugBehavior {
                IncludeExceptionDetailInFaults = true
            });

            var behavior = new ServiceAuthorizationBehavior
            {
                PrincipalPermissionMode = PrincipalPermissionMode.Always
            };

            config.Description.Behaviors.Add(behavior);

            config.AddServiceEndpoint(serviceType, ServiceBinding.CreateBinding(), address);
            return(config);
        }
예제 #2
0
        private static void CallMyService(string jwtToken)
        {
            var xmlToken = WrapJwt(jwtToken);

            var factory = new ChannelFactory <IMyService>(ServiceBinding.CreateBinding(),
                                                          new EndpointAddress(Config.ServiceEndpoint));

            var myService = factory.CreateChannelWithIssuedToken(xmlToken);

            // Call MyService
            string dataId = "001";

            WriteLine($"Create data: {dataId}", ConsoleColor.White);
            try
            {
                // Call MyService.CreateData
                string result = myService.CreateData(dataId);
                WriteLine($"  {result}", ConsoleColor.Green);
            }
            catch (Exception ex)
            {
                WriteLine($"  Error: {ex.Message}", ConsoleColor.Red);
            }
            Console.WriteLine();

            // Read
            WriteLine($"Read data: {dataId}", ConsoleColor.White);
            try
            {
                // Call MyService.ReadData
                string result = myService.ReadData(dataId);
                WriteLine($"  {result}", ConsoleColor.Green);
            }
            catch (Exception ex)
            {
                WriteLine($"  Error: {ex.Message}", ConsoleColor.Red);
            }
            Console.WriteLine();

            // Update
            WriteLine($"Update data: {dataId}", ConsoleColor.White);
            try
            {
                // Call MyService.UpdateData
                string result = myService.UpdateData(dataId);
                WriteLine($"  {result}", ConsoleColor.Green);
            }
            catch (Exception ex)
            {
                WriteLine($"  Error: {ex.Message}", ConsoleColor.Red);
            }
            Console.WriteLine();

            // Delete
            WriteLine($"Delete data: {dataId}", ConsoleColor.White);
            try
            {
                // Call MyService.DeleteData
                string result = myService.DeleteData(dataId);
                WriteLine($"  {result}", ConsoleColor.Green);
            }
            catch (Exception ex)
            {
                WriteLine($"  Error: {ex.Message}", ConsoleColor.Red);
            }
            Console.WriteLine();
        }