Beispiel #1
0
        /// <summary>Creates the WCF endpoints</summary>
        /// <param name="fullUri">The URI</param>
        /// <returns>The client class</returns>
        /// <remarks>We need to do this in code because the app.config file is not available in VSTO</remarks>
        public static SpiraService.SoapServiceClient CreateClient_Spira5(Uri baseUri)
        {
            //Create the binding, first. Allow cookies, and allow margest message sizes.
            BasicHttpBinding httpBinding = new BasicHttpBinding();

            httpBinding.AllowCookies           = true;
            httpBinding.MaxBufferSize          = int.MaxValue;
            httpBinding.MaxBufferPoolSize      = int.MaxValue;
            httpBinding.MaxReceivedMessageSize = int.MaxValue;
            httpBinding.ReaderQuotas.MaxStringContentLength = int.MaxValue;
            httpBinding.ReaderQuotas.MaxDepth              = int.MaxValue;
            httpBinding.ReaderQuotas.MaxBytesPerRead       = int.MaxValue;
            httpBinding.ReaderQuotas.MaxNameTableCharCount = int.MaxValue;
            httpBinding.ReaderQuotas.MaxArrayLength        = int.MaxValue;
            httpBinding.CloseTimeout           = new TimeSpan(0, 2, 0);
            httpBinding.OpenTimeout            = new TimeSpan(0, 2, 0);
            httpBinding.ReceiveTimeout         = new TimeSpan(0, 5, 0);
            httpBinding.SendTimeout            = new TimeSpan(0, 5, 0);
            httpBinding.BypassProxyOnLocal     = false;
            httpBinding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
            httpBinding.MessageEncoding        = WSMessageEncoding.Text;
            httpBinding.TextEncoding           = Encoding.UTF8;
            httpBinding.TransferMode           = TransferMode.Buffered;
            httpBinding.UseDefaultWebProxy     = true;
            httpBinding.Security.Mode          = BasicHttpSecurityMode.None;
            httpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
            httpBinding.Security.Transport.ProxyCredentialType  = HttpProxyCredentialType.None;
            httpBinding.Security.Message.ClientCredentialType   = BasicHttpMessageCredentialType.UserName;
            httpBinding.Security.Message.AlgorithmSuite         = System.ServiceModel.Security.SecurityAlgorithmSuite.Default;

            //Handle SSL if necessary
            if (baseUri.Scheme == "https")
            {
                httpBinding.Security.Mode = BasicHttpSecurityMode.Transport;
                httpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;

                //Allow self-signed certificates
                PermissiveCertificatePolicy.Enact("");
            }
            else
            {
                httpBinding.Security.Mode = BasicHttpSecurityMode.None;
            }

            //Create the new client with endpoint and HTTP Binding
            EndpointAddress endpointAddress = new EndpointAddress(baseUri.AbsoluteUri);

            SpiraService.SoapServiceClient spiraSoapService = new SpiraService.SoapServiceClient(httpBinding, endpointAddress);

            //Modify the operation behaviors to allow unlimited objects in the graph
            foreach (var operation in spiraSoapService.Endpoint.Contract.Operations)
            {
                var behavior = operation.Behaviors.Find <DataContractSerializerOperationBehavior>() as DataContractSerializerOperationBehavior;
                if (behavior != null)
                {
                    behavior.MaxItemsInObjectGraph = 2147483647;
                }
            }
            return(spiraSoapService);
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            LoginUser.Current.Reset();
            string username = txtUsername.Text;
            string password = txtPassword.Password;

            PermissiveCertificatePolicy.Enact("CN=HTTPS-Server");
            BicycleWorldSalesServiceClient proxy = new BicycleWorldSalesServiceClient("wsHttpBinding_BicycleWorldSalesService");

            proxy.ClientCredentials.UserName.UserName = username;
            proxy.ClientCredentials.UserName.Password = password;
            try
            {
                proxy.Login();
                bool isAdmin = proxy.IsUserAdmin();
                LoginUser.Current.Set(username, password, isAdmin);
                DialogResult = true;
                Authenicated = true;
                this.Close();
            }
            catch (MessageSecurityException ex)
            {
                MessageBox.Show((ex.InnerException != null) ? ex.InnerException.Message : "Login failed.");
                DialogResult = true;
                Authenicated = false;
            }
            catch (Exception)
            {
                MessageBox.Show("Login failed.");
                DialogResult = true;
                Authenicated = false;
            }
        }
Beispiel #3
0
        /// <summary>
        /// Configure the SOAP connection for HTTP or HTTPS depending on what was specified
        /// </summary>
        /// <param name="httpBinding"></param>
        /// <param name="uri"></param>
        /// <remarks>Allows self-signed certs to be used</remarks>
        public static void ConfigureBinding(BasicHttpBinding httpBinding, Uri uri)
        {
            //Handle SSL if necessary
            if (uri.Scheme == "https")
            {
                httpBinding.Security.Mode = BasicHttpSecurityMode.Transport;
                httpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;

                //Allow self-signed certificates
                PermissiveCertificatePolicy.Enact("");
            }
            else
            {
                httpBinding.Security.Mode = BasicHttpSecurityMode.None;
            }
        }
 public static void Enact(string subjectName)
 {
     currentPolicy = new PermissiveCertificatePolicy(subjectName);
 }
Beispiel #5
0
        public static void RunTest()
        {
            PermissiveCertificatePolicy.Enact("CN=HTTPS-Server");
            Console.Write("Initializing Proxy for Category Tests...");
            BicycleWorldServiceClient proxy = new BicycleWorldServiceClient("DefaultBinding_BicycleWorldService_BicycleWorldService");

            Console.WriteLine(" done");

            proxy.ClientCredentials.UserName.UserName = "******";
            proxy.ClientCredentials.UserName.Password = "******";


            try
            {
                Console.WriteLine(proxy.Test());

                Console.WriteLine("Test 1: List all categories");
                var categories = proxy.CategoriesList();
                foreach (var category in categories)
                {
                    Console.WriteLine(" Category ID: {0:000}, Name: {1}", category.ProductCategoryID, category.Name);
                }

                Console.WriteLine("Test 2: Removing all 'TEST' categories");
                foreach (var category in categories.Where(c => c.Name == "TEST"))
                {
                    Console.Write(" Removing ProductCategoryID {0:000}... ", category.ProductCategoryID);
                    if (proxy.RemoveCategory(category.ProductCategoryID))
                    {
                        Console.WriteLine("Removed.");
                    }
                    else
                    {
                        Console.WriteLine("Not removed.");
                    }
                }

                Console.WriteLine("Test 3: Add 'TEST' category");
                int productCategoryID = proxy.AddCategory(new ProductCategory()
                {
                    Name = "TEST",
                });
                Console.WriteLine(" New category added.  ProductCategoryID: {0}", productCategoryID);

                Console.WriteLine(" Test 4: Update 'TEST' category");
                ProductCategory categoryToUpdate = proxy.GetCategory(productCategoryID);
                Console.WriteLine(" Name was: {0}", categoryToUpdate.Name);
                categoryToUpdate.Name = "test";
                categoryToUpdate      = proxy.UpdateCategory(categoryToUpdate);
                categoryToUpdate      = proxy.GetCategory(productCategoryID);
                Console.WriteLine(" Name is now: {0}", categoryToUpdate.Name);

                Console.WriteLine("Test 4: Remove 'TEST' category");
                bool removalSuccessful = proxy.RemoveCategory(productCategoryID);
                Console.WriteLine(" Removal Successful: {0}", removalSuccessful);


                Console.WriteLine();

                // Disconnect from the service
                proxy.Close();
            }
            catch (FaultException <SystemFault> sf)
            {
                Console.WriteLine("SystemFault {0}: {1}\n{2}",
                                  sf.Detail.SystemOperation, sf.Detail.SystemMessage,
                                  sf.Detail.SystemReason);
            }
            catch (FaultException <DatabaseFault> dbf)
            {
                Console.WriteLine("DatabaseFault {0}: {1}\n{2}",
                                  dbf.Detail.DbOperation, dbf.Detail.DbMessage,
                                  dbf.Detail.DbReason);
            }
            catch (FaultException e)
            {
                Console.WriteLine("{0}: {1}", e.Code.Name, e.Reason);
            }
            catch (Exception e)
            {
                Console.WriteLine("General exception: {0}", e.Message);
                Console.WriteLine("Inner Exception: {0}", e.InnerException);
            }

            //Console.WriteLine("Press ENTER to continue");
            //Console.ReadLine();
        }
 private static void Main(string[] args)
 {
     PermissiveCertificatePolicy.Enact(RCertName);
     using (MyClient proxy = new MyClient("Ws2007HttpBinding_IHistory"))
     {
Beispiel #7
0
        public static void RunTest()
        {
            PermissiveCertificatePolicy.Enact("CN=HTTPS-Server");
            Console.Write("Initializing Sales Proxy...");
            BicycleWorldSalesServiceClient proxy = new BicycleWorldSalesServiceClient("wsHttpBinding_BicycleWorldSalesService");

            Console.WriteLine(" done");

            proxy.ClientCredentials.UserName.UserName = "******";
            proxy.ClientCredentials.UserName.Password = "******";

            // Test the operations in the service

            try
            {
                Console.WriteLine(proxy.Test());

                // The encrypted list will timeout for slightly large lists (in the hundreds), so the list is
                // being grabbed in smaller chunks.  Transaction logic is used to lock the list while the list is being
                // grabbed.
                TransactionOptions transactionOptions = new TransactionOptions();
                transactionOptions.IsolationLevel = IsolationLevel.RepeatableRead;
                transactionOptions.Timeout        = new TimeSpan(0, 2, 0);
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew, transactionOptions))
                {
                    Console.WriteLine("Test 1: List all Sales Orders");
                    int take  = 5;
                    int count = proxy.GetSalesOrderListCount();
                    for (int skip = 0; skip < count; skip = skip + take)
                    {
                        var salesOrders = proxy.GetSalesOrderList(take, skip);
                        foreach (var saleOrder in salesOrders)
                        {
                            Console.WriteLine(" Sales Order ID: {0:000}", saleOrder.SalesOrderID);
                            foreach (var item in saleOrder.SalesOrderItems)
                            {
                                Console.WriteLine("     Item Price: {0}, Item Quantity: {1}", item.ActualCost, item.Quantity);
                                Console.WriteLine("     Name: {0}, Product Number: {1}", item.Product.Name, item.Product.ProductNumber);
                            }
                        }
                    }

                    //No scope.Complete here as no write tasks are being scoped.

                    scope.Dispose();
                }

                Console.WriteLine();

                // Disconnect from the service
                proxy.Close();
            }
            catch (FaultException <SystemFault> sf)
            {
                Console.WriteLine("SystemFault {0}: {1}\n{2}",
                                  sf.Detail.SystemOperation, sf.Detail.SystemMessage,
                                  sf.Detail.SystemReason);
            }
            catch (FaultException <DatabaseFault> dbf)
            {
                Console.WriteLine("DatabaseFault {0}: {1}\n{2}",
                                  dbf.Detail.DbOperation, dbf.Detail.DbMessage,
                                  dbf.Detail.DbReason);
            }
            catch (FaultException e)
            {
                Console.WriteLine("{0}: {1}", e.Code.Name, e.Reason);
            }
            catch (Exception e)
            {
                Console.WriteLine("General exception: {0}", e.Message);
                Console.WriteLine("Inner Exception: {0}", e.InnerException);
            }

            //Console.WriteLine("Press ENTER to continue");
            //Console.ReadLine();
        }
        public static void RunTest()
        {
            // Create a proxy object and connect to the service
            PermissiveCertificatePolicy.Enact("CN=HTTPS-Server");
            Console.Write("Initializing Product Proxy...");
            BicycleWorldServiceClient proxy = new BicycleWorldServiceClient("DefaultBinding_BicycleWorldService_BicycleWorldService");

            Console.WriteLine(" done");

            proxy.ClientCredentials.UserName.UserName = "******";
            proxy.ClientCredentials.UserName.Password = "******";


            // Test the operations in the service

            try
            {
                Console.WriteLine(proxy.Test());

                // Obtain a list of all products
                Console.WriteLine("Test 1: List all products");
                var products = proxy.ProductList();
                foreach (var product in products)
                {
                    Console.WriteLine(" Product ID: {0:000}, ProductNumber: {1}", product.ProductID, product.ProductNumber);
                }

                Console.WriteLine("Test 2: Removing all 'TEST' products");
                foreach (var product in products.Where(p => p.ProductNumber == "TEST"))
                {
                    Console.Write(" Removing productID {0:000}... ", product.ProductID);
                    if (proxy.RemoveProduct(product.ProductID))
                    {
                        Console.WriteLine("Removed.");
                    }
                    else
                    {
                        Console.WriteLine("Not removed.");
                    }
                }

                Console.WriteLine("Test 3: Add 'TEST' product");
                int productID = proxy.AddProduct(new Product()
                {
                    Name               = "Test",
                    Color              = "RED",
                    ListPrice          = (decimal)3.99,
                    ProductCategoryID  = 1,
                    ProductDescription = "Test Mountain bike",
                    ProductNumber      = "TEST",
                    Quantity           = 5,
                });
                Console.WriteLine(" New producted added.  ProductID: {0}", productID);

                Console.WriteLine(" Test 4: Update 'TEST' product");
                Product productToUpdate = proxy.GetProduct(productID);
                Console.WriteLine(" Price was: {0}", productToUpdate.ListPrice);
                productToUpdate.ListPrice = (decimal)7.99;
                productToUpdate           = proxy.UpdateProduct(productToUpdate);
                productToUpdate           = proxy.GetProduct(productID);
                Console.WriteLine(" Price is now: {0}", productToUpdate.ListPrice);

                Console.WriteLine("Test 4: Remove 'TEST' product");
                bool removalSuccessful = proxy.RemoveProduct(productID);
                Console.WriteLine(" Removal Successful: {0}", removalSuccessful);


                Console.WriteLine();

                // Disconnect from the service
                proxy.Close();
            }
            catch (FaultException <SystemFault> sf)
            {
                Console.WriteLine("SystemFault {0}: {1}\n{2}",
                                  sf.Detail.SystemOperation, sf.Detail.SystemMessage,
                                  sf.Detail.SystemReason);
            }
            catch (FaultException <DatabaseFault> dbf)
            {
                Console.WriteLine("DatabaseFault {0}: {1}\n{2}",
                                  dbf.Detail.DbOperation, dbf.Detail.DbMessage,
                                  dbf.Detail.DbReason);
            }
            catch (FaultException e)
            {
                Console.WriteLine("{0}: {1}", e.Code.Name, e.Reason);
            }
            catch (Exception e)
            {
                Console.WriteLine("General exception: {0}", e.Message);
                Console.WriteLine("Inner Exception: {0}", e.InnerException);
            }

            //Console.WriteLine("Press ENTER to continue");
            //Console.ReadLine();
        }
Beispiel #9
0
 public static void Enact(string subjectName)
 {
     currentPolicy = new PermissiveCertificatePolicy(subjectName);
 }
Beispiel #10
0
        static void Main()
        {
            Console.WriteLine("Username authentication required.");
            Console.WriteLine("Provide a valid machine or domain account. [domain\\user]");
            Console.WriteLine("   Enter username:"******"   Enter password:"******"*");
            }

            Console.WriteLine();

            // WARNING: This code is only needed for test certificates such as those created by makecert. It is
            // not recommended for production code.
            PermissiveCertificatePolicy.Enact("CN=ServiceModelSamples-HTTPS-Server");

            // Create a client with given client endpoint configuration
            CalculatorClient client = new CalculatorClient();

            // Setup the UserName credential
            client.ClientCredentials.UserName.UserName = username;
            client.ClientCredentials.UserName.Password = password.ToString();

            // Call the GetCallerIdentity service operation
            Console.WriteLine(client.GetCallerIdentity());

            // Call the Add service operation.
            double value1 = 100.00D;
            double value2 = 15.99D;
            double result = client.Add(value1, value2);

            Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);


            // Call the Subtract service operation.
            value1 = 145.00D;
            value2 = 76.54D;
            result = client.Subtract(value1, value2);
            Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result);

            // Call the Multiply service operation.
            value1 = 9.00D;
            value2 = 81.25D;
            result = client.Multiply(value1, value2);
            Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);

            // Call the Divide service operation.
            value1 = 22.00D;
            value2 = 7.00D;
            result = client.Divide(value1, value2);
            Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);

            client.Close();

            Console.WriteLine();
            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();
        }
        public static void RunTestRemoveAndCheckoutItems()
        {
            PermissiveCertificatePolicy.Enact("CN=HTTPS-Server");
            Console.Write("Initializing Sales Proxy...");
            BicycleWorldSalesServiceClient proxy = new BicycleWorldSalesServiceClient("wsHttpBinding_BicycleWorldSalesService");

            Console.WriteLine(" done");

            proxy.ClientCredentials.UserName.UserName = "******";
            proxy.ClientCredentials.UserName.Password = "******";

            // Test the operations in the service

            try
            {
                //Console.WriteLine(proxy.Login());


                Console.WriteLine("Press ENTER to start shopping cart");
                Console.ReadLine();

                TransactionOptions transactionOptions = new TransactionOptions();
                transactionOptions.IsolationLevel = IsolationLevel.RepeatableRead;
                transactionOptions.Timeout        = new TimeSpan(0, 1, 0);
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew, transactionOptions))
                {
                    IDictionary <string, string> context = null;
                    IContextManager contextManager       = proxy.InnerChannel.GetProperty <IContextManager>();
                    if (context != null)
                    {
                        contextManager.SetContext(context);
                    }

                    proxy.AddItemToCart("BK-M18B-42");

                    if (context == null)
                    {
                        context = contextManager.GetContext();
                    }

                    Console.WriteLine(proxy.GetShoppingCart());

                    proxy.RemoveItemFromCart("BK-R19B-44");

                    Console.WriteLine(proxy.GetShoppingCart());

                    if (proxy.Checkout())
                    {
                        scope.Complete();
                        Console.WriteLine("Goods purchased.");
                    }
                }

                Console.WriteLine();

                // Disconnect from the service
                proxy.Close();
            }
            catch (FaultException <SystemFault> sf)
            {
                Console.WriteLine("SystemFault {0}: {1}\n{2}",
                                  sf.Detail.SystemOperation, sf.Detail.SystemMessage,
                                  sf.Detail.SystemReason);
            }
            catch (FaultException <DatabaseFault> dbf)
            {
                Console.WriteLine("DatabaseFault {0}: {1}\n{2}",
                                  dbf.Detail.DbOperation, dbf.Detail.DbMessage,
                                  dbf.Detail.DbReason);
            }
            catch (FaultException e)
            {
                Console.WriteLine("{0}: {1}", e.Code.Name, e.Reason);
            }
            catch (Exception e)
            {
                Console.WriteLine("General exception: {0}", e.Message);
                Console.WriteLine("Inner Exception: {0}", e.InnerException);
            }

            Console.WriteLine("Press ENTER to continue");
            Console.ReadLine();
        }
Beispiel #12
0
        public static void Wait()
        {
            PermissiveCertificatePolicy.Enact("CN=HTTPS-Server");

            bool productServiceIsRunning = false;

            Console.Write("Waiting for Product Service... ");
            while (!productServiceIsRunning)
            {
                System.Threading.Thread.Sleep(500);

                try
                {
                    BicycleWorldServiceClient proxy = new BicycleWorldServiceClient("DefaultBinding_BicycleWorldService_BicycleWorldService");
                    proxy.ClientCredentials.UserName.UserName = "******";
                    proxy.ClientCredentials.UserName.Password = "******";
                    proxy.Login();
                    productServiceIsRunning = true;
                    proxy.Abort();

                    Console.WriteLine("Connected.");
                }
                catch (ServerTooBusyException)
                {
                    Console.Write(".");
                }
                catch (SecurityAccessDeniedException ex)
                {
                    Console.WriteLine("\n {0}", ex.Message);
                    break;
                }
                catch (Exception ex)
                {
                    Console.Write(ex.Message);
                }
            }

            bool salesServiceIsRunning = false;

            Console.Write("Waiting for Sales Service... ");
            while (!salesServiceIsRunning)
            {
                System.Threading.Thread.Sleep(500);

                try
                {
                    BicycleWorldSalesServiceClient proxy = new BicycleWorldSalesServiceClient("wsHttpBinding_BicycleWorldSalesService");
                    proxy.ClientCredentials.UserName.UserName = "******";
                    proxy.ClientCredentials.UserName.Password = "******";
                    proxy.Login();
                    salesServiceIsRunning = true;
                    proxy.Abort();

                    Console.WriteLine("Connected.");
                }
                catch (ServerTooBusyException)
                {
                    Console.Write(".");
                }
                catch (Exception ex)
                {
                    Console.Write(ex.Message);
                }
            }
        }