废话就不多说了,开始。。。
对于一款企业级的CRM系统在实际的使用过程中不与外界停止交换是不可能的。在博文《Dynamics CRM 2011编程系列(55):Dynamics CRM 集成开辟简述 》中,我就Dynamics CRM的集成开辟概念做了总结。本文将介绍如何使用BCS(Business Connectivity Service)来实现Dynamics CRM与Sharepoint 2010 的集成,Sharepoint 亦是款微软的重量级产品,它是企业门户,文档管理,协同办公,商务智能的一体化解决方案的产品。
本文将介绍如何通过BCS在Sharepoint站点上表现Dynamics CRM中的实体数据,并且Sharepoint的用户还可以对这些数据停止CRUD操纵。先来看下程序的实现效果吧:
图1
图2
图3
图4
图5
1. 创建一个能对Dynamics CRM 2011系统停止CRUD的WCF Service并把它部署在IIS上。
2. 在安装了Sharepoint的呆板上新建BCS项目
3. 在BCS项目中引用之前创建的Service,并实现响应的CRUD逻辑。
4. 部署BCS项目
5. 配置Sharepoint的External List,让其引用我们部署胜利的BCS项目
在步调1)中,我们为什么不直接使用Dynamics CRM 2011的原生服务呢,原因:sharepoint 2010的BCS项目是基于.Net Frameworks 3.5,无法引用基于4.0框架开辟的WCF Service。在步调2)中,我们只能在安装了sharepoint的呆板上创建BCS项目,至于具体原因不明。接下来我们就需要实现集成开辟的第一步:实现一个基于CRUD的WCF Service,在本文中我会给出个小例子给大家,当然大家完全可以实现自己的CRUD小例子:
[ServiceContract] public interface ICURD { [OperationContract] IEnumerable<Account> GetAllAccount(); [OperationContract] Account GetAccount(string accNumber); [OperationContract] Account CreateAccount(Account acc); [OperationContract] void UpdateAccount(Account acc); [OperationContract] void DeleteAccount(Account acc); } [DataContract] public class Account { [DataMember] public string Number; [DataMember] public string Name; [DataMember] public string Email; [DataMember] public string PhoneNumber; [DataMember] public string Address; } public class CURD : ICURD { private IOrganizationService svc = CrmSvcHelper.CreateService(); public IEnumerable<Account> GetAllAccount() { List<Account> result = new List<Account>(); Account tmpAccount; QueryExpression query = new QueryExpression(); query.ColumnSet = new ColumnSet(true); query.EntityName = "account"; EntityCollection tmpResult = svc.RetrieveMultiple(query); foreach (var item in tmpResult.Entities) { tmpAccount = new Account(); tmpAccount.Number = item.GetAttributeValue<string>("accountnumber"); tmpAccount.Name = item.GetAttributeValue<string>("name"); tmpAccount.Address = item.GetAttributeValue<string>("address1_line1"); tmpAccount.Email = item.GetAttributeValue<string>("emailaddress1"); tmpAccount.PhoneNumber = item.GetAttributeValue<string>("telephone1"); result.Add(tmpAccount); } return result; } public Account GetAccount(string accNumber) { Account result = new Account(); QueryExpression query = new QueryExpression(); query.EntityName = "account"; query.ColumnSet = new ColumnSet(true); query.Criteria.AddCondition(new ConditionExpression("accountnumber", ConditionOperator.Equal, accNumber)); EntityCollection tmpResult = svc.RetrieveMultiple(query); if (tmpResult.Entities.Count > 0) { result.Number = tmpResult.Entities[0].GetAttributeValue<string>("accountnumber"); result.Name = tmpResult.Entities[0].GetAttributeValue<string>("name"); result.Address = tmpResult.Entities[0].GetAttributeValue<string>("address1_line1"); result.Email = tmpResult.Entities[0].GetAttributeValue<string>("emailaddress1"); result.PhoneNumber = tmpResult.Entities[0].GetAttributeValue<string>("telephone1"); } return result; } public Account CreateAccount(Account acc) { Entity account = new Entity("account"); account["accountnumber"] = acc.Number; account["name"] = acc.Name; account["address1_line1"] = acc.Address; account["emailaddress1"] = acc.Email; account["telephone1"] = acc.PhoneNumber; svc.Create(account); return acc; } public void UpdateAccount(Account acc) { QueryExpression query = new QueryExpression(); query.EntityName = "account"; query.ColumnSet = new ColumnSet(true); query.Criteria.AddCondition(new ConditionExpression("accountnumber", ConditionOperator.Equal, acc.Number)); EntityCollection tmpResult = svc.RetrieveMultiple(query); if (tmpResult.Entities.Count > 0) { Entity account = new Entity("account"); account["accountid"] = tmpResult.Entities[0].GetAttributeValue<Guid>("accountid"); account["accountnumber"] = acc.Number; account["name"] = acc.Name; account["address1_line1"] = acc.Address; account["emailaddress1"] = acc.Email; account["telephone1"] = acc.PhoneNumber; svc.Update(account); } } public void DeleteAccount(Account acc) { Account result = new Account(); QueryExpression query = new QueryExpression(); query.EntityName = "account"; query.ColumnSet = new ColumnSet(true); query.Criteria.AddCondition(new ConditionExpression("accountnumber", ConditionOperator.Equal, acc.Number)); EntityCollection tmpResult = svc.RetrieveMultiple(query); if (tmpResult.Entities.Count > 0) { svc.Delete("account", tmpResult.Entities[0].GetAttributeValue<Guid>("accountid")); } } }
后续的博文会继续讨论这个话题,比如:BCS项目的创建,External List的配置。
文章结束给大家分享下程序员的一些笑话语录: 人脑与电脑的相同点和不同点,人脑会记忆数字,电脑也会记忆数字;人脑会记忆程序,电脑也会记忆程序,但是人脑具有感知能力,这种能力电脑无法模仿,人的记忆会影响到人做任何事情,但是电脑只有程序软件。比尔还表示,人脑与电脑之间最重要的一个差别就是潜意识。对于人脑存储记忆的特别之处,比尔表示,人脑并不大,但是人脑重要的功能是联络,人脑会把同样的记忆存储在不同的地方,因此记忆读取的速度就不相同,而这种速度取决于使用的频率和知识的重要性。人脑的记忆存储能力会随着年龄增长而退化,同时记忆的质量也会随着年龄退化。经典语录网
--------------------------------- 原创文章 By
集成和实现
---------------------------------