【问题标题】:Using Windows Credentials to instantiate OrganizationServiceProxy in CRM 2011在 CRM 2011 中使用 Windows 凭据实例化 OrganizationServiceProxy
【发布时间】:2011-09-12 15:31:26
【问题描述】:

是否有人尝试使用 Windows 凭据在 CRM 2011 (On-Premise) 中创建 OrganizationServiceProxy 实例?我有一个使用

的 WCF 服务
      <security mode="TransportCredentialOnly">
        <transport clientCredentialType="Windows"/>
      </security>

并且我能够确认用户已通过身份验证 (OperationContext.Current.ServiceSecurityContext.WindowsIdentity.IsAuthenticated),但我不知道如何生成/传递 ClientCredentials 以创建 CRM 服务的实例。这是从一个 Silverlight 应用程序调用的,该应用程序不在 CRM 的 IFrame 中。

谢谢。

【问题讨论】:

    标签: silverlight wcf security credentials dynamics-crm-2011


    【解决方案1】:

    您需要使用单独的用户帐户登录OrganizationServiceProxy。 您将无法检索 Windows 凭据以传递给代理进行身份验证。

    您使用的用户需要与之关联的prvActOnBehalfOfAnotherUser 权限。

    完成此操作后,您可以成功登录并检索有效的 OrganizationServiceProxy,作为服务的使用者,您需要做的是在调用操作时指定 CallerId。您应该使用 Xrm.Page.context.getUserId 从 xrm 模型中检索此令牌。看。 http://msdn.microsoft.com/en-us/library/gg334511.aspx.

    然后从silverlight,您将使用System.Windows.Browser.ScriptObject 网桥执行客户端javascript 以检索当前用户登录到crm 的用户ID。 最好在应用程序引导时执行此操作,并将值保存到 applicationdata 变量中,以便可以从您的 silverlight 应用程序中全局访问它。

    例如。客户端脚本。

    function CrmContext() {
    }
    
    var context = null;
    with (window.parent) {
        context = Xrm.Page.context;}
    
    CrmContext.prototype.ReadUserId = function () {
       var userId = context.getUserId();
       return userId;
    }
    

    一旦你有了用户令牌,用这个值设置 Proxy CallerId

    例如。

    private OrganizationServiceProxy Proxy { get; set; }
    
    public Guid Create(CreateEntity request)
    {
        if (request == null || request.UserId == Guid.Empty || request.Entity == null)
        {
            throw new InvalidMessageException("Invalid reqest message. Please provide compulsory criteria");
        }
    
        var result = Guid.Empty;
    
        try
        {
            if (Proxy != null)
            {
                Proxy.CallerId = request.UserId;
    
                using (Proxy)
                {
                    result = Proxy.Create(request.Entity);
                }
            }
        }
        catch (FaultException<OrganizationServiceFault> e)
        {
            Log.Error(e.Message);
            throw new IntegrationException(e.Message);
        }
    
        return result;
    }
    

    我解决这个问题的方法是创建一个封装 crm 代理的 crm 适配器,并将请求对象发送到包含用户令牌的服务接口。

    public OrganizationServiceAdapter(ICrmConfigurationContext crmConfigurationConext)
    {
        try
        {
            Proxy = new OrganizationServiceProxy(
                crmConfigurationConext.OrganizationServiceConfiguration,
                crmConfigurationConext.Credentials);
        }
        catch (Exception e)
        {
            //// TODO: Add local proxy pattern implementation for failover
            Proxy = null;
            Log.Error(e.Message);
            throw new IntegrationException(ExceptionMessages.CouldNotLoginToOrganizationService());
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-05
      • 2011-08-05
      • 1970-01-01
      • 1970-01-01
      • 2012-08-22
      • 2011-11-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多