示例#1
0
        public void InitService(string m_strToken)
        {
            // create Web Service client
            string           url     = Properties.Settings.Default.WebServiceUrl;
            BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);

            // remove buffet limmit
            binding.MaxBufferSize          = int.MaxValue;
            binding.MaxReceivedMessageSize = int.MaxValue;
            // binding.ReceiveTimeout =

            //try to read Software\\Tilde\\LetsMT\\url registry string entry and it it exists replace the link
            try
            {
                Microsoft.Win32.RegistryKey key;
                key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\\Tilde\\LetsMT");
                if (key != null)
                {
                    string RegUrl = key.GetValue("url", "none").ToString();
                    if (RegUrl.Length > 3)
                    {
                        if (RegUrl.Substring(0, 4) == "http")
                        {
                            url = RegUrl;
                        }
                    }
                }
            }
            catch (Exception) { }



            EndpointAddress endpoint = new EndpointAddress(url);


            //TODO: HACK {
            // Attach custom Certificate validator to pass validation of untrusted development certificate
            // TODO: This should be removed when trusted CA certificate will be used (or callback method have to do harder checking)
            // ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(ValidateRemoteCertificate);
            //TODO: HACK }

            //binding.Security.Transport.
            //if (m_strAppID != "")
            //{
            //    binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
            //}
            //else
            //{
            //    binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
            //}
            binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
            m_service = new LetsMTAPI.TranslationServiceContractClient(binding, endpoint);

            HeaderManagerMessageInspector inspector          = new HeaderManagerMessageInspector("client-id", m_strToken);
            InspectorBehaviour            addUserIdBehaviour = new InspectorBehaviour(inspector);

            m_service.Endpoint.Behaviors.Add(addUserIdBehaviour);
            ReaderQuotaExtensionBehaviour increaseQuotaBehaviour = new ReaderQuotaExtensionBehaviour();

            m_service.Endpoint.Behaviors.Add(increaseQuotaBehaviour);

            // m_service.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.PeerTrust;

            m_profileCollection = null;
        }
示例#2
0
        //NOT USED FOR NOW

        private bool ValidateCredentialsLocaly(string username, string password, string appID)
        {
            global::System.Resources.ResourceManager resourceManager = new global::System.Resources.ResourceManager("LetsMT.MTProvider.PluginResources", typeof(PluginResources).Assembly);
            // create Web Service client
            string url = resourceManager.GetString("WebServiceUrl");

            try
            {
                Microsoft.Win32.RegistryKey key;
                key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\\Tilde\\LetsMT");
                if (key != null)
                {
                    string RegUrl = key.GetValue("url", "none").ToString();
                    if (RegUrl.Length > 3)
                    {
                        if (RegUrl.Substring(0, 4) == "http")
                        {
                            url = RegUrl;
                        }
                    }
                }
            }
            catch (Exception) { }

            EndpointAddress endpoint = new EndpointAddress(url);

            BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);

            binding.MaxBufferSize          = int.MaxValue;
            binding.MaxReceivedMessageSize = int.MaxValue;


            binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;

            LetsMTAPI.TranslationServiceContractClient TestService = new LetsMTAPI.TranslationServiceContractClient(binding, endpoint);

            TestService.ClientCredentials.UserName.UserName = username;
            TestService.ClientCredentials.UserName.Password = password;


            bool bCredentialsValid = true;

            try
            {
                TestService.GetUserInfo(appID);
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("The HTTP request is unauthorized"))
                {
                    MessageBox.Show("Unrecognized username or password.", "Validation error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    bCredentialsValid = false;
                }
                else
                {
                    MessageBox.Show(ex.ToString());
                    MessageBox.Show(ex.Message);
                    MessageBox.Show("Cannot connect to server.", "Validation error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    bCredentialsValid = false;
                }
            }


            return(bCredentialsValid);
        }