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

0

When I try to execute a CRM CRUD operation using a Console App, I'm getting the following error:

System.ServiceModel.Security.MessageSecurityException   HResult=0x80131501   Message=An unsecured or incorrectly secured fault was received from the other party. See the inner FaultException for the fault code and detail.   Source=mscorlib

class Program
{

    static void Main(string[] args)
    {
         IOrganizationService _serviceProxy = crmConnection();

         Entity con = new Entity("contact");
         con["lastname"] = "test"; 
         _serviceProxy.Create(con);
    }
    private static IOrganizationService crmConnection()
    {
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
    Uri oUri = new Uri("https://XXXXXXXX.api.crm.dynamics.com/XRMServices/2011/Organization.svc");          
    ClientCredentials clientCredentials = new ClientCredentials();
    clientCredentials.UserName.UserName = "XXXXXXXXXXXX";
    clientCredentials.UserName.Password = "XXXXXXXXXXXXXXXXXX";  
    OrganizationServiceProxy _serviceProxy = new OrganizationServiceProxy(oUri, null,clientCredentials,null);
    _serviceProxy.Timeout = new TimeSpan(0, 10, 0);
    return _serviceProxy;
    }
}

Thanks in advance.

An unsecured or incorrectly secured fault was received from the other party

dynamics-crm
dynamics-365
asked on Stack Overflow May 7, 2019 by Sidhu • edited May 10, 2019 by Arun Vinoth

1 Answer

0

Try using Connection String with XrmTooling this way you can avoid call directly to the Organization.svc and handle the redirection to the SDK

var conn = new CrmServiceClient("AuthType=Office365;Username=xxx@xxx.com; Password=yyyyyy;Url=https://xxxx.crm.dynamics.com;RequireNewInstance=True");
IOrganizationService _orgService = conn.OrganizationWebProxyClient ?? (IOrganizationService)conn.OrganizationServiceProxy;
return _orgService;  

If the error continues could be related to differences between your PC time and the Dynamics Server ajusted +-4 minutes and try again.

Hope it helps

answered on Stack Overflow Jul 23, 2019 by Marcelo Acosta Díaz • edited Jul 23, 2019 by Marcelo Acosta Díaz

User contributions licensed under CC BY-SA 3.0