2012-08-31 124 views
1

我正在編寫一個獨立的服務(並非最嚴格意義上的插件),以便使用SDK定期更新Dynamics CRM 2011。Dynamics 2011 SDK IServiceProvider

我的代碼包含以下內容:

// 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

[/編輯]

回答

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做你所需要的。