Working with CRM 2011 WCF Service in SharePoint 2010

 

CRM 2011 WCF services are developed in .Net Framework 4.0 so for integrating with SharePoint kindly use wsdl endpoint of the service and we would not be able to utilize the SDK for the same due to framework differences.
Programmability scenarios
The following diagram illustrates the key programmability scenarios for Microsoft Dynamics CRM 2011.
clip_image001
WCF Services
Following is the list of services exposed by CRM 2011
http://server:portnumber/XRMDeployment/2011/Deployment.svc
http://server: portnumber /XRMServices/2011/Discovery.svc
http://server: portnumber /XRMServices/2011/Organization.svc
Code Sample
Following code sample is for getting all open records for specified entities
//Create the New Instance of CRMService
OrganizationServiceClient service;
string orgserviceURL = string.Empty;
orgserviceURL = string.Empty;
ClientCredentials credentials = new ClientCredentials();
System.Net.NetworkCredential credential = new System.Net.NetworkCredential("user", "password", "domain");
DiscoveryServiceClient client = new DiscoveryServiceClient("CustomBinding_IDiscoveryService", "http://rsv-crm2011.spsocial.:5555/XRMServices/2011/Discovery.svc");
client.ClientCredentials.Windows.ClientCredential = credential;//(NetworkCredential)CredentialCache.DefaultCredentials; RetrieveOrganizationRequest request = new RetrieveOrganizationRequest()
{
UniqueName = "crm11"
};
RetrieveOrganizationResponse response = (RetrieveOrganizationResponse)client.Execute(request);
foreach (KeyValuePair<EndpointType, string> endpoint in response.Detail.Endpoints)
{
if (EndpointType.OrganizationService == endpoint.Key)
{
orgserviceURL = endpoint.Value;
}
}
service = new OrganizationServiceClient("CustomBinding_IOrganizationService", new EndpointAddress(orgserviceURL));
service.ClientCredentials.Windows.ClientCredential = credential;
ColumnSet columns = new ColumnSet();
if ("contact" == entityName) columns.Columns = new List<string> { "contactid", "fullname", "emailaddress1", "parentcustomerid", "telephone1", "statecode" };
if ("lead" == entityName) columns.Columns = new List<string> { "fullname", "createdon", "subject", "statuscode" };
if ("account" == entityName) columns.Columns = new List<string> { "accountid", "name", "address1_telephone1", "address1_city", "emailaddress1", "statecode", "primarycontactid" };
QueryExpression query = new QueryExpression();
query.EntityName = entityName;
query.ColumnSet = columns;
query.Criteria = new FilterExpression();
query.Criteria.FilterOperator = LogicalOperator.And;
ConditionExpression conditionExpr = new ConditionExpression();
conditionExpr.AttributeName = "statecode";
conditionExpr.Operator = ConditionOperator.Equal;
conditionExpr.Values = new List<object> { 0 };
query.Criteria.Conditions = new List<ConditionExpression> { conditionExpr };
EntityCollection entities = service.RetrieveMultiple(query);

Comments