コード例 #1
0
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            // Initial binding
            tbs[0] = new TestBinding();
            tbs[1] = new TestBinding();
            tbs[2] = new TestBinding();

            tbs[0].Name = "Elliot Saba";
            tbs[0].Address = "Campus box #352350";

            tbs[1].Name = "Les Atlas";
            tbs[1].Address = "Campus box #314159";

            tbs[2].Name = "Shwetak Patel";
            tbs[2].Address = "Campus box #271828";

            for (int i = 3; i < 10; ++i)
            {
                tbs[i] = new TestBinding();
                tbs[i].Name = "Student #" + i;
                tbs[i].Address = "Student Address #" + i;
            }
            list.ItemsSource = tbs;
        }
コード例 #2
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     var tb = new TestBinding();
     tb.Name = "Student #" + (tbs.Count - 3);
     tb.Address = "Student Address #" + (tbs.Count - 3);
     tbs.Add(tb);
 }
コード例 #3
0
        public MainPage()
        {
            InitializeComponent();

            // Create a new TestBinding object, fill it out, and bind it to the ContentPanel
            TestBinding tb = new TestBinding();
            tb.Name = "Elliot Saba";
            tb.Address = "asdf";
            ContentPanel.DataContext = tb;
        }
コード例 #4
0
        async void OnSelectedItem(Object sender, ItemTappedEventArgs e)
        {
            if (e.Item == null)
            {
                return;
            }

            TestBinding detail = e.Item as TestBinding;

            await DisplayAlert("Alert", "=>" + detail.TestBindingString, "OK");

            //await Navigation.PushAsync(new Ledgers());
        }
コード例 #5
0
        public static void SetHostAndProtocol(TestBinding useBinding, string hostName, string appName)
        {
            UseBinding         = useBinding;
            HostName           = hostName;
            s_httpHelloUrl     = "http://" + hostName + "/" + appName + "/Service1.svc";
            s_httpDupUrl       = "http://" + hostName + "/" + appName + "/DuplexService.svc";
            s_httpStreamingUrl = "http://" + hostName + "/" + appName + "/StreamingService.svc";

            s_netHttpHelloUrl        = "http://" + hostName + "/" + appName + "/Service1.svc/nethttp";
            s_netHttpDupUrl          = "ws://" + hostName + "/" + appName + "/DuplexService.svc/websocket";
            s_netHttpDupStreamingUrl = "ws://" + hostName + "/" + appName + "/DuplexStreamingService.svc";

            s_tcpHelloUrl     = "net.tcp://" + hostName + ":808/" + appName + "/Service1.svc";
            s_tcpDupUrl       = "net.tcp://" + hostName + ":808/" + appName + "/DuplexService.svc";
            s_tcpStreamingUrl = "net.tcp://" + hostName + ":808/" + appName + "/StreamingService.svc";
        }
コード例 #6
0
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            var tb = new TestBinding();
            tb.Name = "Elliot Saba";
            tb.Address = "Campus box #352350";
            tbs.Add(tb);

            tb = new TestBinding();
            tb.Name = "Les Atlas";
            tb.Address = "Campus box #314159";
            tbs.Add(tb);

            tb = new TestBinding();
            tb.Name = "Shwetak Patel";
            tb.Address = "Campus box #271828";
            tbs.Add(tb);
            list.ItemsSource = tbs;
        }
コード例 #7
0
        // This is one-stop setup for TestHelpers methods to start doing the desired work.
        public static void SetHelperParameters(
            TestBinding useBinding,
            string hostName,
            string appName,
            int selfHostPortStartingNumber,
            int numSelfHostPorts,
            // security-related parameters
            SecurityMode bindingSecurityMode,
            HttpClientCredentialType httpClientCredentialType,
            TcpClientCredentialType tcpClientCredentialType,
            string serverDnsEndpointIdentity,
            string clientCertThumbprint,
            StoreName clientCertStoreName,
            StoreLocation clientCertStoreLocation,
            int openTimeoutMSecs, int closeTimeoutMSecs, int receiveTimeoutMSecs, int sendTimeoutMSecs,
            int customConnectionPoolSize,
            bool debugMode
            )
        {
            UseBinding      = useBinding;
            s_debugMode     = debugMode;
            s_hostName      = hostName;
            s_selfHostPorts = numSelfHostPorts;

            s_bindingSecurityMode       = bindingSecurityMode;
            s_httpClientCredentialType  = httpClientCredentialType;
            s_tcpClientCredentialType   = tcpClientCredentialType;
            s_serverDnsEndpointIdentity = serverDnsEndpointIdentity;
            s_clientCertThumbprint      = clientCertThumbprint;
            s_clientCertStoreLocation   = clientCertStoreLocation;
            s_clientCertStoreName       = clientCertStoreName;

            s_openTimeoutMSeconds    = openTimeoutMSecs;
            s_closeTimeoutMSeconds   = closeTimeoutMSecs;
            s_receiveTimeoutMSeconds = receiveTimeoutMSecs;
            s_sendTimeoutMSeconds    = sendTimeoutMSecs;

            s_customConnectionPoolSize = customConnectionPoolSize;

            //
            // validate security parameters to make it easier to identify incorrect ones
            //
            if (bindingSecurityMode == SecurityMode.Transport)
            {
                // For cert auth we need:
                if (httpClientCredentialType == HttpClientCredentialType.Certificate || tcpClientCredentialType == TcpClientCredentialType.Certificate)
                {
                    // a thumbprint
                    if (string.IsNullOrEmpty(clientCertThumbprint))
                    {
                        throw new ArgumentException("Client certificate thumbprint must be provided for certificate authentication");
                    }
                    // server's DNS endpoint identity string
                    if (string.IsNullOrEmpty(serverDnsEndpointIdentity))
                    {
                        throw new ArgumentException("Server's DNS endpoint identity must be provided for certificate authentication");
                    }

                    // WCF authentication errors are not always informative so we place some diagnostics here
                    if (debugMode)
                    {
                        using (X509Store store = new X509Store(s_clientCertStoreName, s_clientCertStoreLocation))
                        {
                            Console.WriteLine(String.Format("Looking for cert in store: {0} location:{1}",
                                                            s_clientCertStoreName.ToString(), s_clientCertStoreLocation.ToString()));
                            store.Open(OpenFlags.ReadOnly);
                            X509Certificate2Collection foundCertificates = store.Certificates.Find(X509FindType.FindByThumbprint, clientCertThumbprint, false);
                            foreach (var cert in foundCertificates)
                            {
                                string hasPrivateKey, dnsName = "", altDnsName = "", privateKeys = "";
                                try
                                {
                                    dnsName = cert.GetNameInfo(X509NameType.DnsName, false);
                                }
                                catch { }
                                try
                                {
                                    altDnsName = cert.GetNameInfo(X509NameType.DnsFromAlternativeName, false);
                                }
                                catch { }
                                try
                                {
                                    hasPrivateKey = cert.HasPrivateKey.ToString();
                                }
                                catch (Exception e)
                                {
                                    hasPrivateKey = e.Message;
                                }
                                try
                                {
                                    privateKeys += "RSA key: " + (cert.GetRSAPrivateKey()?.KeySize).ToString();
                                }
                                catch (Exception ee)
                                {
                                    privateKeys = ee.Message;
                                }
                                Console.WriteLine(String.Format("Found cert with Name: {0}, Authority: {1}, Subject {2}, Has private key: {3}, privateKeyLength: {4} dnsName: {5}, altDnsName: {6} .",
                                                                cert.FriendlyName, cert.Issuer, cert.Subject, hasPrivateKey, privateKeys, dnsName, altDnsName));
                            }
                        }
                    }
                }
            }
            else if (bindingSecurityMode == SecurityMode.None)
            {
                // Reject incompatible parameters
                if (s_httpClientCredentialType != HttpClientCredentialType.None || s_tcpClientCredentialType != TcpClientCredentialType.None)
                {
                    throw new ArgumentException(String.Format("Client credential types ({0} {1}) are incompatible with binding security mode {2}",
                                                              s_httpClientCredentialType, s_tcpClientCredentialType, bindingSecurityMode));
                }
            }
            else
            {
                throw new ArgumentException("Only SecurityMode.None and SecurityMode.Transport are supported", "bindingSecurityMode");
            }

            // pre-set urls
            s_httpHelloUrl = "http://" + hostName + "/" + appName + "/Service1.svc";
            MultiPortUrlHelper(selfHostPortStartingNumber, numSelfHostPorts, hostName, "http://{0}:{1}/Service1.svc", out s_sh_httpHelloUrls);
            s_httpsHelloUrl = "https://" + hostName + "/" + appName + "/Service1.svc";
            MultiPortUrlHelper(selfHostPortStartingNumber, numSelfHostPorts, hostName, "https://{0}:{1}/Service1.svc", out s_sh_httpsHelloUrls);
            s_httpStreamingUrl = "http://" + hostName + "/" + appName + "/StreamingService.svc";
            MultiPortUrlHelper(selfHostPortStartingNumber, numSelfHostPorts, hostName, "http://{0}:{1}/StreamingService.svc", out s_sh_httpStreamingUrls);
            s_httpsStreamingUrl = "https://" + hostName + "/" + appName + "/StreamingService.svc";
            MultiPortUrlHelper(selfHostPortStartingNumber, numSelfHostPorts, hostName, "https://{0}:{1}/StreamingService.svc", out s_sh_httpsStreamingUrls);
            s_httpDuplexUrl = "http://" + hostName + "/" + appName + "/DuplexService.svc";

            s_tcpHelloUrl = "net.tcp://" + hostName + ":808/" + appName + "/Service1.svc";
            MultiPortUrlHelper(selfHostPortStartingNumber, numSelfHostPorts, hostName, "net.tcp://{0}:{1}/Service1.svc", out s_sh_tcpHelloUrls);
            s_tcpDupUrl = "net.tcp://" + hostName + ":808/" + appName + "/DuplexService.svc";
            MultiPortUrlHelper(selfHostPortStartingNumber, numSelfHostPorts, hostName, "net.tcp://{0}:{1}/DuplexService.svc", out s_sh_tcpDupUrls);
            s_tcpStreamingUrl = "net.tcp://" + hostName + ":808/" + appName + "/StreamingService.svc";
            MultiPortUrlHelper(selfHostPortStartingNumber, numSelfHostPorts, hostName, "net.tcp://{0}:{1}/StreamingService.svc", out s_sh_tcpStreamingUrls);

            s_netHttpHelloUrl = "ws://" + hostName + "/" + appName + "/Service1.svc/websocket";
            MultiPortUrlHelper(selfHostPortStartingNumber, numSelfHostPorts, hostName, "net.tcp://{0}:{1}/Service1.svc/nethttp", out s_sh_netHttpHelloUrl);
            s_netHttpDupUrl = "ws://" + hostName + "/" + appName + "/DuplexService.svc/websocket";
            MultiPortUrlHelper(selfHostPortStartingNumber, numSelfHostPorts, hostName, "net.tcp://{0}:{1}/DuplexService.svc/websocket", out s_sh_netHttpDupUrl);
            s_netHttpStreamingUrl = "ws://" + hostName + "/" + appName + "/StreamingService.svc/websocket";
            MultiPortUrlHelper(selfHostPortStartingNumber, numSelfHostPorts, hostName, "net.tcp://{0}:{1}/StreamingService.svc", out s_sh_netHttpStreamingUrl);
            s_netHttpDupStreamingUrl = "ws://" + hostName + "/" + appName + "/DuplexStreamingService.svc";
            MultiPortUrlHelper(selfHostPortStartingNumber, numSelfHostPorts, hostName, "net.tcp://{0}:{1}/DuplexStreamingService.svc", out s_sh_netHttpDupStreamingUrl);
        }