Exemple #1
0
        private static BlogServiceClient CreateBlogServiceClient(string username, string password)
        {
            BlogServiceClient blogServiceClient = null;
            System.ServiceModel.BasicHttpBinding basicHttpbinding = new System.ServiceModel.BasicHttpBinding(System.ServiceModel.BasicHttpSecurityMode.None);
            basicHttpbinding.Name = "BasicHttpBinding_IBlogService";
            basicHttpbinding.MaxReceivedMessageSize = 2147483646;
            basicHttpbinding.MaxBufferSize = 2147483646;
            basicHttpbinding.MaxBufferPoolSize = 2147483646;

            basicHttpbinding.ReaderQuotas.MaxArrayLength = 2147483646;
            basicHttpbinding.ReaderQuotas.MaxStringContentLength = 5242880;
            basicHttpbinding.SendTimeout = new TimeSpan(0, 5, 0);
            basicHttpbinding.CloseTimeout = new TimeSpan(0, 5, 0);

            basicHttpbinding.Security.Mode = BasicHttpSecurityMode.None;
            basicHttpbinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;

            System.ServiceModel.EndpointAddress endpointAddress = new System.ServiceModel.EndpointAddress(hostURI);

            blogServiceClient = new BlogServiceClient(basicHttpbinding, endpointAddress);

            blogServiceClient.ChannelFactory.Endpoint.Behaviors.Add(new AuthenticationInspectorBehavior());
            ClientAuthenticationHeaderContext.HeaderInformation.Username = username;
            ClientAuthenticationHeaderContext.HeaderInformation.Password = password;

            return blogServiceClient;
        }
Exemple #2
0
        static void ReadPosts()
        {
            try
            {
                // Create a simple client
                BlogServiceClient blogClient = CreateBlogServiceClient();
                using (new OperationContextScope(blogClient.InnerChannel))
                {
                    var headerData = GenerateEncryptedHeader("chris", "sakell");

                    MessageHeader aMessageHeader = MessageHeader.CreateHeader("authentication-header", "chsakell.com", headerData);
                    OperationContext.Current.OutgoingMessageHeaders.Add(aMessageHeader);

                    List <Post> blogPosts = blogClient.ReadPosts();

                    foreach (Post post in blogPosts)
                    {
                        Console.WriteLine(post.Title);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #3
0
        private static BlogServiceClient CreateBlogServiceClient(string username, string password)
        {
            BlogServiceClient blogServiceClient = null;

            System.ServiceModel.BasicHttpBinding basicHttpbinding = new System.ServiceModel.BasicHttpBinding(System.ServiceModel.BasicHttpSecurityMode.None);
            basicHttpbinding.Name = "BasicHttpBinding_IBlogService";
            basicHttpbinding.MaxReceivedMessageSize = 2147483646;
            basicHttpbinding.MaxBufferSize          = 2147483646;
            basicHttpbinding.MaxBufferPoolSize      = 2147483646;

            basicHttpbinding.ReaderQuotas.MaxArrayLength         = 2147483646;
            basicHttpbinding.ReaderQuotas.MaxStringContentLength = 5242880;
            basicHttpbinding.SendTimeout  = new TimeSpan(0, 5, 0);
            basicHttpbinding.CloseTimeout = new TimeSpan(0, 5, 0);

            basicHttpbinding.Security.Mode = BasicHttpSecurityMode.None;
            basicHttpbinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;

            System.ServiceModel.EndpointAddress endpointAddress = new System.ServiceModel.EndpointAddress(hostURI);

            blogServiceClient = new BlogServiceClient(basicHttpbinding, endpointAddress);

            blogServiceClient.ChannelFactory.Endpoint.Behaviors.Add(new AuthenticationInspectorBehavior());
            ClientAuthenticationHeaderContext.HeaderInformation.Username = username;
            ClientAuthenticationHeaderContext.HeaderInformation.Password = password;

            return(blogServiceClient);
        }
Exemple #4
0
        /// <inheritdoc />
        protected override void BeginProcessing()
        {
            base.BeginProcessing();
            var binding = new BasicHttpBinding();

            Client = new BlogServiceClient(binding, new EndpointAddress(ServiceUrl));
            WriteVerbose($"Connecting to {ServiceUrl} ...");
        }
Exemple #5
0
 public BlogConsumer(Channel channel)
 {
     _channel     = channel;
     _blog        = new Blog();
     _blogRequest = new BlogRequest()
     {
         Blog = _blog
     };
     _blogServiceClient = new BlogServiceClient(_channel);
 }
Exemple #6
0
        static void ReadBlogPosts()
        {
            try
            {
                BlogServiceClient client    = CreateBlogServiceClient("chris", "sakell");
                List <Post>       blogPosts = client.ReadPosts();

                foreach (Post post in blogPosts)
                {
                    Console.WriteLine(post.Title);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            Console.ReadKey();
        }
Exemple #7
0
        private static BlogServiceClient CreateBlogServiceClient()
        {
            BlogServiceClient blogServiceClient = null;
            System.ServiceModel.BasicHttpBinding basicHttpbinding = new System.ServiceModel.BasicHttpBinding(System.ServiceModel.BasicHttpSecurityMode.None);
            basicHttpbinding.Name = "BasicHttpBinding_IBlogService";
            basicHttpbinding.MaxReceivedMessageSize = 2147483646;
            basicHttpbinding.MaxBufferSize = 2147483646;
            basicHttpbinding.MaxBufferPoolSize = 2147483646;

            basicHttpbinding.ReaderQuotas.MaxArrayLength = 2147483646;
            basicHttpbinding.ReaderQuotas.MaxStringContentLength = 5242880;
            basicHttpbinding.SendTimeout = new TimeSpan(0, 5, 0);
            basicHttpbinding.CloseTimeout = new TimeSpan(0, 5, 0);

            basicHttpbinding.Security.Mode = BasicHttpSecurityMode.None;
            basicHttpbinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;

            System.ServiceModel.EndpointAddress endpointAddress = new System.ServiceModel.EndpointAddress(hostURI);

            blogServiceClient = new BlogServiceClient(basicHttpbinding, endpointAddress);

            return blogServiceClient;
        }
Exemple #8
0
        private static BlogServiceClient CreateBlogServiceClient()
        {
            BlogServiceClient blogServiceClient = null;

            System.ServiceModel.BasicHttpBinding basicHttpbinding = new System.ServiceModel.BasicHttpBinding(System.ServiceModel.BasicHttpSecurityMode.None);
            basicHttpbinding.Name = "BasicHttpBinding_IBlogService";
            basicHttpbinding.MaxReceivedMessageSize = 2147483646;
            basicHttpbinding.MaxBufferSize          = 2147483646;
            basicHttpbinding.MaxBufferPoolSize      = 2147483646;

            basicHttpbinding.ReaderQuotas.MaxArrayLength         = 2147483646;
            basicHttpbinding.ReaderQuotas.MaxStringContentLength = 5242880;
            basicHttpbinding.SendTimeout  = new TimeSpan(0, 5, 0);
            basicHttpbinding.CloseTimeout = new TimeSpan(0, 5, 0);

            basicHttpbinding.Security.Mode = BasicHttpSecurityMode.None;
            basicHttpbinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;

            System.ServiceModel.EndpointAddress endpointAddress = new System.ServiceModel.EndpointAddress(hostURI);

            blogServiceClient = new BlogServiceClient(basicHttpbinding, endpointAddress);

            return(blogServiceClient);
        }