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

Sidhu
  • 19
  • 2
  • 9
  • This may already be answered: https://stackoverflow.com/questions/1484601/wcf-gives-an-unsecured-or-incorrectly-secured-fault-error. If not, please provide more detail including the code you are using. – Zach Mast May 07 '19 at 11:58
  • Thank you for your responce.Added code – Sidhu May 07 '19 at 12:39

1 Answers1

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