【问题标题】:An unsecured or incorrectly secured fault was received from the other party. See the inner FaultException for the fault code and detail从另一方收到不安全或不正确安全的故障。故障代码和细节见内部FaultException
【发布时间】:2019-05-07 05:20:57
【问题描述】:

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

System.ServiceModel.Security.MessageSecurityException H结果=0x80131501 消息=从另一方收到不安全或不正确安全的故障。有关故障代码和详细信息,请参阅内部 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

【问题讨论】:

标签: dynamics-crm dynamics-365


【解决方案1】:

尝试使用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 分钟之间的差异有关,然后重试。

希望对你有帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多