1

我正在尝试访问 WCF 服务(MS CRM 2011)并收到上述错误。如果我使用 Cassini 或 IIS Express 从 VS2010 调试器运行我的示例程序,它会很好地工作。没有身份验证错误。

但是,如果我将站点发布到本地 IIS 7.5(运行 Windows 7 64 位),我会在获取 CRM UserId (WhoAmIResponse) 的行上收到错误消息。

我打开 Fiddler 来比较在调试器下运行和在 IIS 下运行之间的请求。在 IIS 下运行的站点上,请求甚至从未遇到过,因此在到达那一步之前它必须失败。

发布到 IIS 的站点将其 web.config 设置为...

    <authentication mode="Windows">
    </authentication>
    <identity impersonate="true"/>

该站点在预装的 ASP.NET v4.0 应用程序池、集成管道模式、ApplicationPoolIdentity 帐户下运行。

这是我的代码...

public class DemoController : Controller
{
    public ActionResult Index()
    {
        ClientCredentials credentials = new ClientCredentials();
        credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;

        var _serviceProxy = new OrganizationServiceProxy(new Uri("http://svr-rex2011-dev/TimeEntry/XRMServices/2011/Organization.svc"),
                                                            null,
                                                            credentials,
                                                            null);

        // This statement is required to enable early-bound type support.
        _serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());

        IOrganizationService service = (IOrganizationService)_serviceProxy;

        // Display information about the logged on user.
        Guid userid = ((WhoAmIResponse)service.Execute(new WhoAmIRequest())).UserId;
        SystemUser systemUser = (SystemUser)service.Retrieve("systemuser", userid,
            new ColumnSet(new string[] { "firstname", "lastname" }));

        // Retrieve the version of Microsoft Dynamics CRM.
        RetrieveVersionRequest versionRequest = new RetrieveVersionRequest();
        RetrieveVersionResponse versionResponse =
            (RetrieveVersionResponse)service.Execute(versionRequest);

        ViewBag.FirstName = systemUser.FirstName;
        ViewBag.LastName = systemUser.LastName;
        ViewBag.Version = versionResponse.Version;

        return View();
    }

}

有任何想法吗?非常感激!!!

4

2 回答 2

2

您描述的情况似乎是这样的:当您的应用程序在 IIS 上运行时尝试访问 CRM 服务时,您会遇到身份验证错误。当您从 Visual Studio 或 IIS Express 运行您的应用程序时,您不会遇到身份验证错误。

如果这是真的,我很确定您的问题是由于用于为您的应用程序运行 IIS AppPool 的身份造成的。您需要将 AppPool 身份更改为对 CRM 服务具有网络访问权限的身份。通常它应该是具有正确权限的域帐户,但是有一些方法可以使用具有相同密码的本地计算机帐户来执行此操作(如果域可用,则绝对不推荐)。

于 2011-05-12T18:42:06.063 回答
0

我遇到了同样的问题,就我而言,结果证明是由于 CRM 是负载平衡的。事实证明,通过 Kerberos 进行的身份验证委托在负载平衡架构中不起作用

我们通过绕过负载平衡的 HOST 条目将我们的应用程序直接指向其中一个 CRM 服务器来解决这个问题。

我希望这可以节省我花费的几个小时。

于 2013-05-08T04:44:25.517 回答