Beispiel #1
0
        private void ConfigureContainer()
        {
            var builder = new ContainerBuilder();

            builder.RegisterControllers(typeof(MvcApplication).Assembly);
            builder.RegisterModelBinders(typeof(MvcApplication).Assembly);
            builder.RegisterModelBinderProvider();
            builder.RegisterModule <AutofacWebTypesModule>();
            builder.RegisterSource(new ViewRegistrationSource());
            builder.RegisterFilterProvider();
            builder
            .Register(c => new ChannelFactory <IPetService>(
                          new WSHttpBinding(),
                          new EndpointAddress("http://localhost:61897/PetService.svc")))
            .SingleInstance();
            builder
            .Register(context =>
            {
                var client = new PetServiceClient();
                if (client.ClientCredentials != null)
                {
                    client.ClientCredentials.UserName.UserName = "******";
                }
                return(client);
            })
            .As <IPetService>()
            .UseWcfSafeRelease();

            var container = builder.Build();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
Beispiel #2
0
        public async Task <ActionResult> Index()
        {
            var client = new PetServiceClient();

            client.ClientCredentials.UserName.UserName = "******";
            var result = await client.GetPetsAsync();

            var pets = await _petService.GetPetsAsync();

            return(Content(string.Join(" ", pets.Select(x => x.Name + " " + x.Type))));
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            _client  = new PetServiceClient();
            _key     = _client.RegisterClient("Test");
            _running = true;

            while (_running)
            {
                Console.Write(@"Input: ");
                string[] input = Console.ReadLine().Trim().Split(',');

                if (input[0] == "exit")
                {
                    _running = false;
                }
                else if (input[0] == "listen")
                {
                    _client.GetPetOwnerAsync();
                }
                else if (input[0] == "set")
                {
                    if (input.Count() >= 4)
                    {
                        if (input[1] == "PetOwner")
                        {
                            _client.AddPetOwner(_key, new PetOwner()
                            {
                                Name = input[2], Occupation = input[3]
                            });
                        }
                        else if (input[1] == "Pet")
                        {
                        }
                    }
                }
            }
        }