Dynamics 2011 SDK IServiceProvider

时间:2012-08-31 13:19:02

标签: c# sdk dynamics-crm dynamics-crm-2011

我正在编写一个独立服务(不是最严格意义上的插件),使用SDK定期更新Dynamics CRM 2011。

我的代码包括以下内容:

// Get entity metadata so we can process attributes correctly
IPluginExecutionContext context = (IPluginExecutionContext)ServiceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)ServiceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
... (etc)

这需要一个ServiceProvider类的实例[实现IServiceProvider],但我不知道如何获取它。

那么,我该怎么做呢?

由于

[编辑]

我目前正在考虑使用ServerConnection作为替代方案。

http://msdn.microsoft.com/en-us/library/gg309393.aspx

[/编辑]

1 个答案:

答案 0 :(得分:0)

我把它分类了。

来自http://markuserlandsson.wordpress.com/2011/01/26/my-first-crm-2011-project-part-1/

(为了安全起见,此处转载)

ClientCredentials credentials = new ClientCredentials();
credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;

IServiceConfiguration<IOrganizationService> config = 
        ServiceConfigurationFactory.CreateConfiguration<IOrganizationService>(
        new Uri(Properties.Settings.Default.CrmUrl));
config.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());

OrganizationServiceProxy proxy = new OrganizationServiceProxy(config, credentials);
OrganizationServiceContext context = new OrganizationServiceContext(proxy);

然后使用此proxycontext来执行您需要的操作。

相关问题