Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

C# Exception create Cew Contact

(0) ShareShare
ReportReport
Posted on by 690

Good morning everyone,

I'm running a code that creates a new contact in MSCRM, but when trying to create I get the following message Exception

"A failure protected incorrectly or not protected was received from the other party. See internal FaultException for details of the fault code."

What can it be? Below the code I'm using.

try
{
else
{
conexaocrm string = "Url = http: // intranet: 5555 / Training: Username = admin, password = admin @ 15";
Microsoft.Xrm.Client.CrmConnection connection = Microsoft.Xrm.Client.CrmConnection.Parse (conexaocrm);

using (Microsoft.Xrm.Client.Services.OrganizationService orgService = new Microsoft.Xrm.Client.Services.OrganizationService (connection))
{
Entity contact = new Entity ( "contact");
contact [ "firstname"] = name;
contact [ "lastname"] = name;
contact [ "new_cpf"] = cpf;
contact [ "emailaddress1"] = email;
contact [ "telephone1"] = tel_comercial;
contact [ "birthdate"] = Convert.ToDateTime (dt_nascimento);
Guid = ContactID orgService.Create (contact);

Entity account = new Entity ( "account");
account [ "name"] = "Test Account";
EntityReference EntityReference primarycontactid = new ( "contact" ContactID);
account [ "primarycontactid"] = primarycontactid;
Guid = accountId orgService.Create (account);
}
}
}
catch (Exception ex)
{
Console.WriteLine ( "Error reading CRM Base:" + ex.Message);
}

*This post is locked for comments

  • RE: C# Exception create Cew Contact

    OK. Tank You

  • Verified answer
    RE: C# Exception create Cew Contact

    Hi,

    Since it is working when you restart the server there's nothing wrong with the code the issue is the virtual machine, which isn't really a CRM issue and you might be lucky that someone in this group is a VM wiz but you would probably be more fortunate in a VM group.

    Hope you can find a resolution to this!

    Regards

  • RE: C# Exception create Cew Contact

    Hello everyone,

    I am using the method below to connect the organization ON Premises, call the service CRM and create a new occurrence.

    But this method of calling the service is not working as it loses connection in some way and need to restart my virtual machine that is my server and restart my notebook.

    After doing this I can create occurred normally, but can not have to keep restarting my notebook ever, much less the server.

    If anyone has one other way to call and access the CRM server appreciate.

    I am using CRM 2015 on Premises ... below the code.


    protected void btnSave_Click (object sender, EventArgs e)
            {
                try
                {
                    conexaocrm string = "Url = http: // intranet: 5555 / Training: Username = admin, password = admin @ 15";
                    Microsoft.Xrm.Client.CrmConnection connection = Microsoft.Xrm.Client.CrmConnection.Parse (conexaocrm);

                    using (Microsoft.Xrm.Client.Services.OrganizationService orgService = new Microsoft.Xrm.Client.Services.OrganizationService (connection))
                    {
                        Entity incident = new Entity ( "incident");
                        incident [ "title"] = TextBoxTitulo.Text;
                        Incident [ "caseorigincode"] = new OptionSetValue (3);
                        incident [ "new_logradouro"] = TextBoxLogradouro.Text;
                        incident [ "new_numero"] = TextBoxNumero.Text;
                        incident [ "new_complemento"] = TextBoxComplemento.Text;
                        incident [ "new_bairro"] = TextBoxBairro.Text;
                        incident [ "new_cidade"] = TextBoxCidade.Text;
                        incident [ "new_estado"] = TextBoxEstado.Text;
                        incident [ "new_contatoresponsavel"] = TextBoxContatoResponsavel.Text;
                        incident [ "new_telefone"] = LabelTelefone.Text;
                        incident [ "description"] = TextBoxDescricao.Text;
                        

                        Guid customerid = new Guid (TextBoxClienteID.Text);
                        EntityReference EntityReference CustomerId = new ( "account", customerid);
                        incident [ "customerid"] = CustomerId;

                        Guid equipamentoid = new Guid (TextBoxEquipamentoID.Text);
                        EntityReference EntityReference EquipamentoId = new ( "new_equipamentos" equipamentoid);
                        incident [ "new_equipamentoid"] = EquipamentoId;

                        Guid = incidentID orgService.Create (incident);

                        / * Function that blocks all fields in the form * /
                        BloqueiaCampos ();
                    }
                }
                catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> ex)
                {
                    Response.Write ( "Error reading CRM Base:" + ex.Message);
                }
            }
            #endregion

    Thank you all for your help.

  • RE: C# Exception create Cew Contact

    Hello,

    Thanks for answering....

    Yes, I saved the virtual machine, the other day to work I need to restart the virtual machine, and restarting the server


    It is likely that you are actually losing connectivity vm because I reinicicio the virtual machine and back to work,.

    What do you correct it? Put fixed IP on the server? Another way to get the service?


    Do you have another form of connectivity to CRM services

    Tank You.

  • Aiden Kaskela Profile Picture
    Aiden Kaskela 19,692 on at
    RE: C# Exception create Cew Contact

    Hi Ricardo,

    Are you saying that your code works after a restart of the VM but it'll stop working again at some point? That sounds like your code is fine but the machine isn't stable - either the CRM services are getting pegged or the VM is losing connectivity over the course of the day.

    Thanks,

     Aiden

  • RE: C# Exception create Cew Contact

    Thanks for the answer

    Could you please help me with an example or tell me where I can put in my example this code?

    Thank you

  • RE: C# Exception create Cew Contact

    Hi,

    What happens if you replace your two creates with a

    WhoAmIResponse resp = ((WhoAmIResponse)_service.Execute(new WhoAmIRequest()));

    That just does a query of who is logged in and will show if you're connected in a correct way.

    Regards

  • RE: C# Exception create Cew Contact

    Thanks for the answer.


    You have the example of another method of connection?

    I'm using a virtual machine as MSCRM Server when I restart the virtual machine I can create the contact again using to create all day.

    When I open the virtual machine the other day and that this error occurs.

    What can this be?

    The following example of the connection of code I'm using:

    conexaocrm string = "Url = http: // intranet: 5555 / Training: Username = admin, password = admin @ 15";
                                Microsoft.Xrm.Client.CrmConnection connection = Microsoft.Xrm.Client.CrmConnection.Parse (conexaocrm);

                                using (Microsoft.Xrm.Client.Services.OrganizationService orgService = new Microsoft.Xrm.Client.Services.OrganizationService (connection))
                                {
                                    Entity account = new Entity ( "account");
                                    account [ "name"] = name;
                                    account [ "telephone1"] = phone;
                                    account [ "new_cnpj"] = cnpj;
                                    Guid = accountId orgService.Create (account);
                                }

    Thank you

  • Aiden Kaskela Profile Picture
    Aiden Kaskela 19,692 on at
    RE: C# Exception create Cew Contact

    Hi Ricardo,

    This is probably an issue connecting to the CRM instance, I'd verify all the connection information. Try running a simple query to see if you still get the problem, that'll point to it being in the connection vs the actual create method.

    Hope this helps! I'd appreciate if you'd mark this as Answering your question.

    Thanks,

     Aiden

  • RE: C# Exception create Cew Contact

    3666.Sem-t_ED00_tulo.jpgThanks for the reply, even putting the exception, for it on the line:

    Entity contact = new entity ("contact")

                                     contact ["firstname"] = name;

                                     contact ["lastname"] = name;

                                     contact ["new_cpf"] = cpf;

                                     contact ["emailaddress1"] = email;

                                     contact ["telephone1"] = tel_comercial;

                                     contact ["birthdate"] = Convert.ToDateTime (dt_nascimento);

                                     Guid = ContactID orgService.Create (contact);

    A protected or unprotected incorrectly failure was received from the other party. See internal FaultException for details of fault code

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,253 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans