示例#1
0
        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();
        }
示例#3
0
 /// <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();
 }
示例#4
0
 /// <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());
     }
 }
示例#6
0
 /// <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();
 }
示例#7
0
        /// <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;
            }
        }
示例#8
0
        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);
 }
示例#10
0
 /// <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;
 }