接收到来自另一方的不安全或不正确安全的故障。有关错误代码和详细信息,请参见内部FaultException。

时间:2019-05-07 05:20:58

标签: dynamics-crm dynamics-365

当我尝试使用控制台应用程序执行CRM CRUD操作时,出现以下错误:

  

System.ServiceModel.Security.MessageSecurityException   HResult = 0x80131501   Message =从另一方收到不安全或不正确安全的故障。有关错误代码和详细信息,请参见内部FaultException。   来源= 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;
    }
}

谢谢。

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

1 个答案:

答案 0 :(得分:0)

尝试以这种方式使用Connection String with XrmTooling可以避免直接调用Organization.svc并处理重定向到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;  

如果错误仍然存​​在,则可能与您的PC时间和Dynamics Server调整的+ -4分钟之间的差异有关,然后重试。

希望有帮助