internal static void AdjustUserNameForWindows(ClientCredentials clientCredentials) { ClientExceptionHelper.ThrowIfNull((object)clientCredentials, nameof(clientCredentials)); if (string.IsNullOrWhiteSpace(clientCredentials.UserName.UserName)) { return; } NetworkCredential networkCredential; if (clientCredentials.UserName.UserName.IndexOf('@') > -1) { string[] strArray = clientCredentials.UserName.UserName.Split('@'); networkCredential = strArray.Length <= 1 ? new NetworkCredential(strArray[0], clientCredentials.UserName.Password) : new NetworkCredential(strArray[0], clientCredentials.UserName.Password, strArray[1]); } else if (clientCredentials.UserName.UserName.IndexOf('\\') > -1) { string[] strArray = clientCredentials.UserName.UserName.Split('\\'); networkCredential = strArray.Length <= 1 ? new NetworkCredential(strArray[0], clientCredentials.UserName.Password) : new NetworkCredential(strArray[1], clientCredentials.UserName.Password, strArray[0]); } else { networkCredential = new NetworkCredential(clientCredentials.UserName.UserName, clientCredentials.UserName.Password); } clientCredentials.Windows.ClientCredential = networkCredential; clientCredentials.UserName.UserName = string.Empty; clientCredentials.UserName.Password = string.Empty; }
/// <summary>Enables support for the early-bound entity types.</summary> public void EnableProxyTypes() { ClientExceptionHelper.ThrowIfNull((object)this.ServiceConfiguration, "ServiceConfiguration"); OrganizationServiceConfiguration serviceConfiguration = this.ServiceConfiguration as OrganizationServiceConfiguration; ClientExceptionHelper.ThrowIfNull((object)serviceConfiguration, "orgConfig"); serviceConfiguration.EnableProxyTypes(); }
/// <summary>Initializes a new instance of the <see cref="T:Microsoft.Xrm.Sdk.Client.ServiceProxy`1"></see> class using a service configuration and client logon credentials.</summary> /// <param name="serviceConfiguration">Type: <see cref="T:Microsoft.Xrm.Sdk.Client.IServiceConfiguration`1"></see>. A service configuration.</param> /// <param name="clientCredentials">Type: Returns_ClientCredentials. The logon credentials of the client.</param> protected ServiceProxy( IServiceConfiguration <TService> serviceConfiguration, ClientCredentials clientCredentials) { ClientExceptionHelper.ThrowIfNull((object)serviceConfiguration, nameof(serviceConfiguration)); ClientExceptionHelper.ThrowIfNull((object)serviceConfiguration.CurrentServiceEndpoint, "serviceConfiguration.CurrentServiceEndpoint"); this.ServiceConfiguration = serviceConfiguration; this.SetClientCredentials(clientCredentials); this.IsAuthenticated = true; //this.SetDefaultEndpointSwitchBehavior(); }
/// <summary>The maximum amount of time a single channel operation has to complete before a timeout fault is raised on a service channel binding.</summary> /// <param name="sendTimeout">Type: Returns_TimeSpan.A send operation timespan.</param> /// <param name="binding">Type: Returns_Binding. The target channel binding.</param> /// <param name="openTimeout">Type: Returns_TimeSpan. An open operation timespan.</param> /// <param name="closeTimeout">Type: Returns_TimeSpan.A close operation timespan.</param> protected static void SetBindingTimeout( Binding binding, TimeSpan sendTimeout, TimeSpan openTimeout, TimeSpan closeTimeout) { ClientExceptionHelper.ThrowIfNull((object)binding, nameof(binding)); binding.OpenTimeout = openTimeout; binding.CloseTimeout = closeTimeout; binding.SendTimeout = sendTimeout; }
public void EnableProxyTypes() { ClientExceptionHelper.ThrowIfNull((object)this.CurrentServiceEndpoint, "CurrentServiceEndpoint"); lock (this._lockObject) { if (this.CurrentServiceEndpoint.EndpointBehaviors.TryGetValue(typeof(ProxyTypesBehavior), out IEndpointBehavior proxyTypesBehavior)) { this.CurrentServiceEndpoint.EndpointBehaviors.Remove((IEndpointBehavior)proxyTypesBehavior); } this.CurrentServiceEndpoint.EndpointBehaviors.Add((IEndpointBehavior) new ProxyTypesBehavior()); } }
/// <summary>Initializes a new instance of the <see cref="T:Microsoft.Xrm.Sdk.Client.ServiceProxy`1"></see> class using a service URI, a home realm URI, client logon credentials, and pn_Windows_Live device credentials.</summary> /// <param name="deviceCredentials">Type: Returns_ClientCredentials. The credentials of a device registered with pn_Windows_Live. Only required when authenticating with pn_CRM_Online, otherwise use null.</param> /// <param name="homeRealmUri">Type: Returns_URI. The URI of the WS-Trust metadata endpoint of a second ADFS instance.</param> /// <param name="uri">Type: Returns_URI. The URI of the service.</param> /// <param name="clientCredentials">Type: Returns_ClientCredentials. The client’s logon credentials.</param> protected ServiceProxy( Uri uri, Uri homeRealmUri, ClientCredentials clientCredentials, ClientCredentials deviceCredentials) { ClientExceptionHelper.ThrowIfNull((object)uri, nameof(uri)); this.IsAuthenticated = false; this.ServiceConfiguration = ServiceConfigurationFactory.CreateConfiguration <TService>(uri); this.SetClientCredentials(clientCredentials); this.HomeRealmUri = homeRealmUri; //this.DeviceCredentials = deviceCredentials; //this.SetDefaultEndpointSwitchBehavior(); }
/// <summary>Authenticates a device with pn_Windows_Live.</summary> /// <returns>Type: <see cref="T:Microsoft.Xrm.Sdk.Client.SecurityTokenResponse"></see>A security token response.</returns> /*protected virtual SecurityTokenResponse AuthenticateDeviceCore() * { * if (this.ServiceConfiguration.AuthenticationType != AuthenticationProviderType.LiveId) * return (SecurityTokenResponse)null; * ClientExceptionHelper.ThrowIfNull((object)this.DeviceCredentials, "DeviceCredentials"); * return this.ServiceConfiguration.AuthenticateDevice(this.DeviceCredentials); * }*/ /// <summary>Authenticates the client with a service.</summary> protected virtual void AuthenticateCore() { ClientExceptionHelper.ThrowIfNull((object)this.ServiceConfiguration, "ServiceConfiguration"); if (this.ServiceConfiguration.AuthenticationType == AuthenticationProviderType.ActiveDirectory) { this.IsAuthenticated = true; } else { if (this.ClientCredentials == null) { return; } // SecurityTokenResponse securityTokenResponse = (SecurityTokenResponse)null; switch (this.ServiceConfiguration.AuthenticationType) { /*case AuthenticationProviderType.Federation: * //securityTokenResponse = this.AuthenticateClaims(); * break; * case AuthenticationProviderType.LiveId: * //securityTokenResponse = this.AuthenticateWithLiveId(); * break; * case AuthenticationProviderType.OnlineFederation: * if (this.ServiceConfiguration.ShouldAuthenticateWithLiveId<TService>(this.ClientCredentials)) * { * AuthenticationCredentials authenticationCredentials = new AuthenticationCredentials(); * authenticationCredentials.ClientCredentials = this.ClientCredentials; * if (this.DeviceCredentials != null) * { * authenticationCredentials.SupportingCredentials = new AuthenticationCredentials(); * authenticationCredentials.SupportingCredentials.ClientCredentials = this.DeviceCredentials; * } * // securityTokenResponse = this.ServiceManagement.Authenticate(authenticationCredentials).SecurityTokenResponse; * break; * } * //securityTokenResponse = this.AuthenticateOnlineFederation(); * break;*/ } /*ClientExceptionHelper.Assert(securityTokenResponse != null && securityTokenResponse.Token != null, "The user authentication failed!"); * this.SecurityTokenResponse = securityTokenResponse;*/ this.IsAuthenticated = true; } }
internal static void ConfigureEndpoint( ServiceEndpoint endpoint, ServiceProxy <TService> serviceProxy) { ClientExceptionHelper.ThrowIfNull((object)endpoint, nameof(endpoint)); ClientExceptionHelper.ThrowIfNull((object)serviceProxy, nameof(serviceProxy)); foreach (OperationDescription operation in (Collection <OperationDescription>)endpoint.Contract.Operations) { DataContractSerializerOperationBehavior operationBehavior = operation.Behaviors.Find <DataContractSerializerOperationBehavior>(); if (operationBehavior != null) { operationBehavior.MaxItemsInObjectGraph = int.MaxValue; } } XrmBinding xrmBinding = new XrmBinding(endpoint.Binding); endpoint.Binding = (Binding)xrmBinding; xrmBinding.MaxReceivedMessageSize = (long)int.MaxValue; xrmBinding.MaxBufferSize = int.MaxValue; xrmBinding.ReaderQuotas.MaxStringContentLength = int.MaxValue; xrmBinding.ReaderQuotas.MaxArrayLength = int.MaxValue; xrmBinding.ReaderQuotas.MaxBytesPerRead = int.MaxValue; ServiceProxy <TService> .SetBindingTimeout((Binding)xrmBinding, serviceProxy.Timeout, serviceProxy.Timeout, serviceProxy.Timeout); }
protected ServiceContextInitializer(Microsoft.Xrm.Sdk.Client.ServiceProxy <TService> proxy) { ClientExceptionHelper.ThrowIfNull((object)proxy, nameof(proxy)); this.ServiceProxy = proxy; this.Initialize(proxy); }
/// <summary>Initializes a new instance of the <see cref="T:Microsoft.Xrm.Sdk.Client.ServiceChannel`1"></see> class using a channel factory. internal</summary> /// <param name="factory">Type: Returns_ChannelFactory_Generic. A channel factory.</param> public ServiceChannel(ChannelFactory <TChannel> factory) { ClientExceptionHelper.ThrowIfNull((object)factory, nameof(factory)); this.Factory = factory; }
private static List <object> Deserialize(string pagingCookie, int pageNumber) { ClientExceptionHelper.ThrowIfNegative(pageNumber, nameof(pageNumber)); List <object> objectList = new List <object>(); try { using (XmlReader xmlReader = PagingCookieHelper.CreateXmlReader(pagingCookie)) { xmlReader.Read(); objectList.Add((object)pageNumber); string attribute1 = xmlReader.GetAttribute("parentEntityId"); if (!string.IsNullOrEmpty(attribute1)) { objectList.Add((object)new Guid(attribute1)); string attribute2 = xmlReader.GetAttribute("parentAttributeName"); ClientExceptionHelper.ThrowIfNullOrEmpty(attribute2, "parentAttributeName"); objectList.Add((object)attribute2); int result = -1; if (int.TryParse(xmlReader.GetAttribute("parentEntityObjectTypeCode"), out result)) { objectList.Add((object)result); } else { ClientExceptionHelper.ThrowIfNegative(result, "parentOtc"); } } while (xmlReader.Read()) { if (xmlReader.NodeType != XmlNodeType.EndElement) { string name = xmlReader.Name; ClientExceptionHelper.ThrowIfNullOrEmpty(name, "field"); objectList.Add((object)name); if (xmlReader.AttributeCount != 2) { throw new NotSupportedException("Malformed XML Passed to in the Paging Cookie. We expect at most two attributes (first/firstNull and last/lastNull)"); } string attribute2 = xmlReader.GetAttribute("last"); if (attribute2 == null) { if (xmlReader.GetAttribute("lastnull") == null) { throw new NotSupportedException("Malformed XML Passed to in the Paging Cookie. Value for attribute last was not specified, and it was not null either."); } objectList.Add((object)null); } else { objectList.Add((object)attribute2); } string attribute3 = xmlReader.GetAttribute("first"); if (attribute3 == null) { if (xmlReader.GetAttribute("firstnull") == null) { throw new NotSupportedException("Malformed XML Passed to in the Paging Cookie. Value for attribute first was not specified, and it was not null either."); } objectList.Add((object)null); } else { objectList.Add((object)attribute3); } } } } } catch (XmlException ex) { throw new NotSupportedException("Malformed XML in the Paging Cookie", (Exception)ex); } catch (FormatException ex) { throw new NotSupportedException("Malformed XML in the Paging Cookie", (Exception)ex); } return(objectList); }
private static string Serialize(object[] pagingElements, out int pageNumber) { pageNumber = 0; if (pagingElements == null || pagingElements.Length == 0) { return((string)null); } if (pagingElements.Length % 3 != 1) { throw new NotSupportedException("Skip token has incorrect length"); } if (pagingElements[0] == null || !(pagingElements[0].GetType() == typeof(int)) || (int)pagingElements[0] < 0) { throw new NotSupportedException("Skip token has incorrect page value"); } pageNumber = (int)pagingElements[0]; using (StringWriter stringWriter = new StringWriter((IFormatProvider)CultureInfo.InvariantCulture)) { using (XmlWriter xmlWriter = PagingCookieHelper.CreateXmlWriter((TextWriter)stringWriter)) { xmlWriter.WriteStartElement("cookie"); xmlWriter.WriteAttributeString("page", pageNumber.ToString((IFormatProvider)CultureInfo.InvariantCulture)); int num = 1; if (pagingElements[1] != null && pagingElements[1].GetType() == typeof(Guid) && (pagingElements[2] != null && pagingElements[2].GetType() == typeof(string)) && (pagingElements[3] != null && pagingElements[3].GetType() == typeof(int))) { num = 4; xmlWriter.WriteAttributeString("parentEntityId", pagingElements[1].ToString()); xmlWriter.WriteAttributeString("parentAttributeName", (string)pagingElements[2]); xmlWriter.WriteAttributeString("parentEntityObjectTypeCode", pagingElements[3].ToString()); } for (int index = num; index < pagingElements.Length; index += 3) { string pagingElement = (string)pagingElements[index]; ClientExceptionHelper.ThrowIfNullOrEmpty(pagingElement, "attributeName"); string empty1 = string.Empty; string empty2 = string.Empty; string str1 = (string)pagingElements[index + 1]; string str2 = (string)pagingElements[index + 2]; xmlWriter.WriteStartElement(pagingElement); string localName1; if (str1 != null) { localName1 = "last"; } else { localName1 = "lastnull"; str1 = "1"; } string localName2; if (str2 != null) { localName2 = "first"; } else { localName2 = "firstnull"; str2 = "1"; } xmlWriter.WriteAttributeString(localName1, str1); xmlWriter.WriteAttributeString(localName2, str2); xmlWriter.WriteEndElement(); } xmlWriter.WriteEndElement(); } return(stringWriter.ToString()); } }