/// <summary> /// Invokes the specified method of the named service. /// </summary> /// <typeparam name="T">The expected return type.</typeparam> /// <param name="serviceName">The name of the service to use.</param> /// <param name="methodName">The name of the method to call.</param> /// <param name="args">The arguments to the method.</param> /// <returns>The return value from the web service method.</returns> public object InvokeMethod(string serviceName, string methodName, params object[] args) { // Create an instance of the specified service // and invoke the method // System.ServiceModel.Channels.Binding defaultBinding = new BasicHttpBinding(BasicHttpSecurityMode.None); if (this.credentials != null) { ((BasicHttpBinding)defaultBinding).Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly; ((BasicHttpBinding)defaultBinding).Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm; } object obj = this.webServiceAssembly.CreateInstance(serviceName, false, BindingFlags.CreateInstance, null, new object[] { defaultBinding, new EndpointAddress(this.webServiceUri.ToString()) }, null, null); Type type = obj.GetType(); if (this.credentials != null) { PropertyInfo piClientCreds = type.GetProperty("ClientCredentials"); ClientCredentials creds = (ClientCredentials)piClientCreds.GetValue(obj, null); PropertyInfo piWindowsCreds = creds.GetType().GetProperty("Windows"); WindowsClientCredential windowsCreds = (WindowsClientCredential)piWindowsCreds.GetValue(creds, null); PropertyInfo piAllowNtlm = windowsCreds.GetType().GetProperty("AllowNtlm"); piAllowNtlm.SetValue(windowsCreds, true, null); PropertyInfo piCredentials = windowsCreds.GetType().GetProperty("ClientCredential"); piCredentials.SetValue(windowsCreds, credentials, null); PropertyInfo piImpersonation = windowsCreds.GetType().GetProperty("AllowedImpersonationLevel"); piImpersonation.SetValue(windowsCreds, System.Security.Principal.TokenImpersonationLevel.Impersonation, null); } return(type.InvokeMember(methodName, BindingFlags.InvokeMethod, null, obj, args)); }
protected ClientCredentials(ClientCredentials other) { if (other == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("other"); } if (other._userName != null) { _userName = new UserNamePasswordClientCredential(other._userName); } if (other._clientCertificate != null) { _clientCertificate = new X509CertificateInitiatorClientCredential(other._clientCertificate); } if (other._serviceCertificate != null) { _serviceCertificate = new X509CertificateRecipientClientCredential(other._serviceCertificate); } if (other._windows != null) { _windows = new WindowsClientCredential(other._windows); } if (other._httpDigest != null) { _httpDigest = new HttpDigestClientCredential(other._httpDigest); } _isReadOnly = other._isReadOnly; }
internal void ApplyConfiguration(WindowsClientCredential windows) { if (windows == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("windows"); } windows.AllowNtlm = this.AllowNtlm; windows.AllowedImpersonationLevel = this.AllowedImpersonationLevel; }
public void Windows() { ClientCredentials c = new ClientCredentials(); WindowsClientCredential win = c.Windows; Assert.IsNotNull(win.ClientCredential, "#1"); Assert.IsTrue(win.AllowNtlm, "#2"); Assert.AreEqual(TokenImpersonationLevel.Identification, win.AllowedImpersonationLevel, "#3"); }
public Connection(string url, string domain, string username, string password) { this.client = new QMSClient("BasicHttpBinding_IQMS", url); WindowsClientCredential creds = client.ClientCredentials.Windows; creds.ClientCredential.Domain = domain; creds.ClientCredential.UserName = username; creds.ClientCredential.Password = password; ServiceKeyClientMessageInspector.ServiceKey = client.GetTimeLimitedServiceKey(); }
/// <summary> /// Invokes the specified method of the named service. /// </summary> /// <typeparam name="T">The expected return type.</typeparam> /// <param name="serviceName">The name of the service to use.</param> /// <param name="methodName">The name of the method to call.</param> /// <param name="args">The arguments to the method.</param> /// <returns>The return value from the web service method.</returns> public object InvokeMethod(string serviceName, string methodName, params object[] args) { // create an instance of the specified service // and invoke the method BasicHttpBinding defaultBinding = new BasicHttpBinding(BasicHttpSecurityMode.None); //System.ServiceModel.Channels.Binding defaultBinding = new BasicHttpBinding(BasicHttpSecurityMode.None); defaultBinding.OpenTimeout = new TimeSpan(0, 5, 0); defaultBinding.CloseTimeout = new TimeSpan(0, 5, 0); defaultBinding.SendTimeout = new TimeSpan(0, 5, 0); defaultBinding.MaxBufferSize = Int32.MaxValue; defaultBinding.MaxReceivedMessageSize = Int32.MaxValue; defaultBinding.MaxBufferPoolSize = Int32.MaxValue; defaultBinding.ReaderQuotas.MaxArrayLength = Int32.MaxValue; defaultBinding.ReaderQuotas.MaxStringContentLength = Int32.MaxValue; defaultBinding.ReaderQuotas.MaxArrayLength = Int32.MaxValue; defaultBinding.ReaderQuotas.MaxBytesPerRead = Int32.MaxValue; defaultBinding.ReaderQuotas.MaxDepth = Int32.MaxValue; defaultBinding.ReaderQuotas.MaxNameTableCharCount = Int32.MaxValue; if (this.credentials != null) { ((BasicHttpBinding)defaultBinding).Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly; ((BasicHttpBinding)defaultBinding).Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm; ((BasicHttpBinding)defaultBinding).MaxBufferSize = Int32.MaxValue; ((BasicHttpBinding)defaultBinding).MaxReceivedMessageSize = Int32.MaxValue; } object obj = this.webServiceAssembly.CreateInstance(serviceName, false, BindingFlags.CreateInstance, null, new object[] { defaultBinding, new EndpointAddress(this.webServiceUri.ToString()) }, null, null); Type type = obj.GetType(); if (this.credentials != null) { PropertyInfo piClientCreds = type.GetProperty("ClientCredentials"); ClientCredentials creds = (ClientCredentials)piClientCreds.GetValue(obj, null); PropertyInfo piWindowsCreds = creds.GetType().GetProperty("Windows"); WindowsClientCredential windowsCreds = (WindowsClientCredential)piWindowsCreds.GetValue(creds, null); PropertyInfo piAllowNtlm = windowsCreds.GetType().GetProperty("AllowNtlm"); piAllowNtlm.SetValue(windowsCreds, true, null); PropertyInfo piCredentials = windowsCreds.GetType().GetProperty("ClientCredential"); piCredentials.SetValue(windowsCreds, credentials, null); PropertyInfo piImpersonation = windowsCreds.GetType().GetProperty("AllowedImpersonationLevel"); piImpersonation.SetValue(windowsCreds, System.Security.Principal.TokenImpersonationLevel.Impersonation, null); } return(type.InvokeMember(methodName, BindingFlags.InvokeMethod, null, obj, args)); }
internal void ApplyConfiguration(WindowsClientCredential windows) { if (windows == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("windows"); } // To suppress AllowNtlm warning. #pragma warning disable 618 windows.AllowNtlm = this.AllowNtlm; #pragma warning restore 618 windows.AllowedImpersonationLevel = this.AllowedImpersonationLevel; }
public void SetClientCredentials(ClientCredentials credentials) { if (credentials != null) { if (credentials.UserName.UserName != null) { UserNamePasswordClientCredential cred = this.proxy.ClientCredentials.UserName; cred.UserName = credentials.UserName.UserName; cred.Password = credentials.UserName.Password; } else { WindowsClientCredential cred = this.proxy.ClientCredentials.Windows; cred.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; } } }
protected ClientCredentials(ClientCredentials other) { if (other == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("other"); } if (other.userName != null) { this.userName = new UserNamePasswordClientCredential(other.userName); } if (other.clientCertificate != null) { this.clientCertificate = new X509CertificateInitiatorClientCredential(other.clientCertificate); } if (other.serviceCertificate != null) { this.serviceCertificate = new X509CertificateRecipientClientCredential(other.serviceCertificate); } if (other.windows != null) { this.windows = new WindowsClientCredential(other.windows); } if (other.httpDigest != null) { this.httpDigest = new HttpDigestClientCredential(other.httpDigest); } if (other.issuedToken != null) { this.issuedToken = new IssuedTokenClientCredential(other.issuedToken); } if (other.peer != null) { this.peer = new PeerCredential(other.peer); } this.getInfoCardTokenCallback = other.getInfoCardTokenCallback; this.supportInteractive = other.supportInteractive; this.securityTokenHandlerCollectionManager = other.securityTokenHandlerCollectionManager; this.useIdentityConfiguration = other.useIdentityConfiguration; this.isReadOnly = other.isReadOnly; }
private void Snippet1() { //<snippet1> // Create a service host. EndpointAddress ea = new EndpointAddress("http://localhost/Calculator"); WSHttpBinding b = new WSHttpBinding(SecurityMode.Message); b.Security.Message.ClientCredentialType = MessageCredentialType.Windows; // Create a client. The code is not shown here. See the WCF samples // for an example of the CalculatorClient code. CalculatorClient cc = new CalculatorClient(b, ea); // Get a reference to the Windows client credential object. WindowsClientCredential winCred = cc.ClientCredentials.Windows; Console.WriteLine("AllowedImpersonationLevel: {0}", winCred.AllowedImpersonationLevel); Console.WriteLine("AllowNtlm: {0}", winCred.AllowNtlm); Console.WriteLine("Domain: {0}", winCred.ClientCredential.Domain); Console.ReadLine(); // Change the AllowedImpersonationLevel. winCred.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; Console.WriteLine("Changed AllowedImpersonationLevel: {0}", winCred.AllowedImpersonationLevel); Console.ReadLine(); // Open the calculator and use it. //cc.Open(); //Console.WriteLine(cc.Add(11, 11)); //// Close the client. //cc.Close(); //</snippet1> }