Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to communicate WCF by creating serviceclient class.
surprisingly I m able to communicate WCF even if I pass wrong domain. it happen only if I pass only domain admin user. with normal IISUser it throws proper validation exception in case of wrong domain.
My test env. in different domain where wcf is hosted and i can able to communicate it by passing wrong domain from remote machine(exist in diff domain).

In below Code I am passing wrong domain name in "DomainName" variable and domain admin user in "UserName" and it works fine. How can i make sure that user has pass correct domain ?

What I have tried:

<pre> WSHttpBinding httpBinding = new WSHttpBinding();
                httpBinding.Name = "WSHttpBinding_IService";
                httpBinding.CloseTimeout = TimeSpan.MaxValue;
                httpBinding.OpenTimeout = TimeSpan.MaxValue;
                httpBinding.ReceiveTimeout = TimeSpan.MaxValue;
                httpBinding.SendTimeout = TimeSpan.MaxValue;
                httpBinding.BypassProxyOnLocal = false;
                httpBinding.TransactionFlow = false;
                httpBinding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
                httpBinding.MaxBufferPoolSize = Convert.ToInt64("2147483646");
                httpBinding.MaxReceivedMessageSize = Convert.ToInt64("2147483646");
                httpBinding.MessageEncoding = WSMessageEncoding.Mtom;
                httpBinding.TextEncoding = Encoding.UTF8;
                httpBinding.UseDefaultWebProxy = true;
                httpBinding.AllowCookies = false;

                httpBinding.ReliableSession.Ordered = true;
                httpBinding.ReliableSession.InactivityTimeout = TimeSpan.MaxValue;
                httpBinding.ReliableSession.Enabled = false;

                if (ServerURL.ToLower().Contains("https://"))
                    httpBinding.Security.Mode = SecurityMode.Transport;
                else
                    httpBinding.Security.Mode = SecurityMode.Message;

                httpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
                httpBinding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;
                httpBinding.Security.Transport.Realm = "";
                

                httpBinding.Security.Message.ClientCredentialType = MessageCredentialType.Windows;
                httpBinding.Security.Message.NegotiateServiceCredential = true;
                httpBinding.Security.Message.AlgorithmSuite = System.ServiceModel.Security.SecurityAlgorithmSuite.Default;

                EndpointAddress endpoint = new EndpointAddress(new Uri(ServerURL + "/Service/MyService.svc"), EndpointIdentity.CreateDnsIdentity("localhost"));
		ServiceClient _serviceClient = new ServiceClient (httpBinding, endpoint);
                _serviceClient.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
                _serviceClient.ClientCredentials.Windows.ClientCredential.Domain = DomainName;
                _serviceClient.ClientCredentials.Windows.ClientCredential.UserName = UserName;
                _serviceClient.ClientCredentials.Windows.ClientCredential.Password = Password;
                _serviceClient.Open();
                string CnfgRbInstalled = _serviceClient.GetAccessToken();


                _serviceClient.Close();
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900