0

从 ASP.NET MVC (.NET 4.5) 我使用 OrganizationServiceProxy 连接到 CRM 服务器,如下所示:

private IOrganizationService GetCrmService(string userName, string password, string domain, Uri serviceUri)
        {
            OrganizationServiceProxy _serviceProxy;

            ClientCredentials credentials = new ClientCredentials();
            credentials.Windows.ClientCredential = new System.Net.NetworkCredential(userName, password, domain);
            ClientCredentials deviceCredentials = new ClientCredentials();

            using (_serviceProxy = new OrganizationServiceProxy(serviceUri, null, credentials, deviceCredentials))
            {
                _serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());
                return (IOrganizationService)_serviceProxy;
            }
        }

在我的开发机器上一切正常,但是当我部署到我指定的 Web 服务器时,它失败了:

[FileNotFoundException: Could not load file or assembly 'Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.]
   Microsoft.Xrm.Sdk.Client.ServiceConfiguration`1.CreateLocalChannelFactory() +0
   Microsoft.Xrm.Sdk.Client.ServiceConfiguration`1.CreateChannelFactory(ClientCredentials clientCredentials) +290
   Microsoft.Xrm.Sdk.Client.OrganizationServiceConfiguration.CreateChannelFactory(ClientCredentials clientCredentials) +16
   Microsoft.Xrm.Sdk.Client.ServiceProxy`1.get_ChannelFactory() +126
   Microsoft.Xrm.Sdk.Client.ServiceProxy`1.CreateNewServiceChannel() +24
   Microsoft.Xrm.Sdk.Client.ServiceContextInitializer`1.Initialize(ServiceProxy`1 proxy) +31
   Microsoft.Xrm.Sdk.Client.OrganizationServiceContextInitializer..ctor(OrganizationServiceProxy proxy) +54
   Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy.RetrieveMultipleCore(QueryBase query) +892

我想激活服务器功能“Windows Identity Foundation 3.5”可以解决这个问题,但我被告知这已经全部被新的 WIF 4.5 类所取代,这些类是 .NET 4.5 框架的一部分。

但我不知道如何重写我的代码或进行必要的更改以进行此切换。

4

0 回答 0