locked
An unsecured or incorrectly secured fault was received from the other party. See the inner FaultException for the fault code and detail. Authentication Failure. RRS feed

  • Question

  • Hi,

    I am trying to learn Microsoft Dynamics CRM from training KIt, currently working on Online CRM while doing this on WCF session for lab ConnectToServer to generate a User ID getting above fault exception on line " var response = OrgService. Execute (req) as WhoAmIResponse"

    Where am i going wrong?

    my code is ..

               

    namespace CycleControllerUI
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            private OrganizationDetail CurrentOrganizationDetail { get; set; }
            private IDiscoveryService DiscoveryService { get; set; }
            private IOrganizationService OrgService { get; set; }
            private ClientCredentials _ClientCreds { get; set; }
            private ClientCredentials _DeviceCreds { get; set; }
            private bool IsLiveID { get; set; }


            public MainWindow()
            {
                InitializeComponent();
            }


            public Uri GetDiscoveryServiceUri(string serverName)
            {
                string discoSuffix = @"/XRMServices/2011/Discovery.svc";

                return new Uri(string.Format("{0}{1}", serverName, discoSuffix));
            }


            private void btnDiscover_Click(object sender, RoutedEventArgs e)
            {
                var discoUri = GetDiscoveryServiceUri(ServerURL.Text);

                IServiceConfiguration<IDiscoveryService> dinfo =
                    ServiceConfigurationFactory.CreateConfiguration<IDiscoveryService>(discoUri);

                _ClientCreds = new ClientCredentials();
                DiscoveryServiceProxy dsp;

                if (GetServerType(discoUri) == AuthenticationProviderType.LiveId)
                {
                    _ClientCreds.UserName.UserName = username.Text;
                    _ClientCreds.UserName.Password = password.Text;

                    _DeviceCreds = DeviceIdManager.LoadOrRegisterDevice();

                    dsp = new DiscoveryServiceProxy(discoUri, null, _ClientCreds, _DeviceCreds);
                    IsLiveID = true;
                }
                else
                {
                    /*_ClientCreds.Windows.ClientCredential.UserName = username.Text;
                    _ClientCreds.Windows.ClientCredential.Password = password.Text;
                    */
                    _ClientCreds.UserName.UserName = username.Text;
                    _ClientCreds.UserName.Password = password.Text;

                    _ClientCreds.Windows.ClientCredential.Domain = domain.Text;

                    dsp = new DiscoveryServiceProxy(dinfo, _ClientCreds);
                    IsLiveID = false;
                }

                dsp.Authenticate();
                var orgRequest = new RetrieveOrganizationsRequest();
                var orgResponse = dsp.Execute(orgRequest) as RetrieveOrganizationsResponse;


                comboOrgs.ItemsSource = orgResponse.Details;

            }

            public AuthenticationProviderType GetServerType(Uri uri)
            {
                return ServiceConfigurationFactory.CreateConfiguration<IDiscoveryService>(uri).AuthenticationType;
            }

            private void btnConnect_Click(object sender, RoutedEventArgs e)
            {
                if (comboOrgs.SelectedItem == null)
                {
                    MessageBox.Show("You must select an organization before connecting");
                    return;
                }
                this.CurrentOrganizationDetail = comboOrgs.SelectedItem as OrganizationDetail;

                Uri orgServiceUri = new Uri(CurrentOrganizationDetail.Endpoints[EndpointType.OrganizationService]);
                if (IsLiveID)
                {
                    OrgService = new OrganizationServiceProxy(orgServiceUri, null, _ClientCreds, _DeviceCreds);
                }
                else
                {
                    IServiceConfiguration<IOrganizationService> orgConfigInfo =
                    ServiceConfigurationFactory.CreateConfiguration<IOrganizationService>(orgServiceUri);
                    OrgService = new OrganizationServiceProxy(orgConfigInfo, _ClientCreds);
                }

                WhoAmIRequest req = new WhoAmIRequest();
                var response = OrgService.Execute(req) as WhoAmIResponse; // Exception on this line
                MessageBox.Show("You are connected as userid " + response.UserId.ToString());


            }

        }
    }

    Thanks


    Saturday, November 2, 2013 6:27 PM