How to use crm.services in crm 2011?? not able to find the dll wsdl in sdk...
-
Monday, April 30, 2012 8:10 AM
Hi All,
I am trying to access Columnset and its attributes to retrieve fields of specific entity from lead page as of now being able to achieve using multiple retrieve but not a feasible solution as far as optimization is concerned trying to use crm.services but not able to find the dll tried finding wsdl in sdk to build and use it in the solution but was not successful so is there a way to include services in crm 2011????? or any workaround for my task???
Thanks
All Replies
-
Monday, April 30, 2012 8:42 AM
You will have to use IOrganizationService class instead of CrmService class in crm 2011.
Here is the sample code that how to connect with crm 2011 and fetch leads data in asp grid.
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { IOrganizationService service = getCRMOnlineService(); getLead(service); } } public IOrganizationService getCRMOnlineService() { Uri OrganizationUri = new Uri("https://*****.api.crm.dynamics.com/XRMServices/2011/Organization.svc"); ////ClientCredentials DeviceCredentials = new ClientCredentials(); ////ClientCredentials Credentials = new ClientCredentials(); //////DeviceCredentials.Windows.ClientCredential = new System.Net.NetworkCredential("username", "Password", "OrganizationName"); ////DeviceCredentials.Windows.ClientCredential.UserName = "11ltfz36jrxd4sdycpkfk7a0gq"; ////DeviceCredentials.Windows.ClientCredential.Password = "aeKwQN#c/V`RR!!ObqFA,Pz7"; ////Credentials.UserName.UserName = "username@hotmail.com"; ////Credentials.UserName.Password = "Password"; var liveIDCreds = new ClientCredentials(); liveIDCreds.UserName.UserName = "username@hotmail.com"; liveIDCreds.UserName.Password = "Password"; var deviceIDcreds = new ClientCredentials(); deviceIDcreds.UserName.UserName = "11ltfz36jrxd4sdycpkfk7a0gq"; deviceIDcreds.UserName.Password = "aeKwQN#c/V`RR!!ObqFA,Pz7"; OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, null, liveIDCreds, deviceIDcreds); serviceProxy.EnableProxyTypes(); IOrganizationService _service = (IOrganizationService)serviceProxy; return _service; } protected void GvLeadData_PageIndexChanging(object sender, GridViewPageEventArgs e) { IOrganizationService _service = getCRMOnlineService(); getLead(_service); GvLeadData.PageIndex = e.NewPageIndex; GvLeadData.DataBind(); } public void getLead(IOrganizationService _service) { var query = new QueryExpression { EntityName = "lead", ColumnSet = new ColumnSet("subject", "fullname", "companyname", "telephone1", "emailaddress1", "statuscode", "createdon", "ownerid"), }; var request = new OrganizationRequest() { RequestName = "RetrieveMultiple" }; request["Query"] = query; try { OrganizationResponse response = _service.Execute(request); EntityCollection results = (EntityCollection)response["EntityCollection"]; DataTable dt = new DataTable(); dt.Columns.Add("Id", Type.GetType("System.Int32")); dt.Columns.Add("Topic", Type.GetType("System.String")); dt.Columns.Add("Name", Type.GetType("System.String")); dt.Columns.Add("Company Name", Type.GetType("System.String")); dt.Columns.Add("Business Phone", Type.GetType("System.String")); dt.Columns.Add("E-mail", Type.GetType("System.String")); dt.Columns.Add("Status Reason", Type.GetType("System.String")); dt.Columns.Add("Created On", Type.GetType("System.DateTime")); dt.Columns.Add("Owner", Type.GetType("System.String")); int idCount = 1; foreach (Entity leads in results.Entities) { DataRow dr; dr = dt.NewRow(); dr["Id"] = idCount++; if (leads.Attributes.Contains("subject")) { dr["Topic"] = leads.Attributes["subject"].ToString(); } if (leads.Attributes.Contains("fullname")) { dr["Name"] = leads.Attributes["fullname"].ToString(); } if (leads.Attributes.Contains("companyname")) { dr["Company Name"] = leads.Attributes["companyname"].ToString(); } if (leads.Attributes.Contains("telephone1")) { dr["Business Phone"] = leads.Attributes["telephone1"].ToString(); } if (leads.Attributes.Contains("emailaddress1")) { dr["E-mail"] = leads.Attributes["emailaddress1"].ToString(); } if (leads.Attributes.Contains("statuscode")) { dr["Status Reason"] = leads.FormattedValues["statuscode"];//leads.Attributes["statuscode"].ToString(); } if (leads.Attributes.Contains("createdon")) { dr["Created On"] = leads.Attributes["createdon"].ToString(); } if (leads.Attributes.Contains("ownerid")) { dr["Owner"] = ((EntityReference)leads.Attributes["ownerid"]).Name.ToString(); } dt.Rows.Add(dr); } this.GvLeadData.Visible = true; GvLeadData.DataSource = dt; GvLeadData.DataBind(); } catch (FaultException falutException) { } catch (System.ServiceModel.Security.MessageSecurityException ex) { } catch (KeyNotFoundException key) { } }
- Proposed As Answer by Dynamics CRM 31 Monday, April 30, 2012 8:42 AM
-
Monday, April 30, 2012 8:59 AM
Thanks Milan for the prompt reply however your solutions seems working fine if we want to retrieve to an aspx page but I am creating a plugin to retrieve the value of the fields from the lead entity so as to use the data for passing the values to my email code in the plugin.
This is the sample code what I am trying :
if (context.InputParameters.Contains("PrincipalAccess"))
{
PrincipalAccess principal = context.InputParameters["PrincipalAccess"] as PrincipalAccess;
EntityReference sharedUser = principal.Principal;
AccessRights accessRights = principal.AccessMask;
// Frame the Query with Entity name, Conditions and Columns.
QueryExpression query = new QueryExpression("lead");
query.ColumnSet = new ColumnSet(true);
ColumnSet cols = new ColumnSet(new String[] { "firstname", "lastname"});
//EntityCollection result = service.RetrieveMultiple(query);
EntityCollection result = service.Retrieve("lead", new Guid(id), cols);
//Entity resultEntity = result.Entities.FirstOrDefault(x => x.Id.Equals(entity.Id));
Entity Leadentity = new Entity("lead");
the above code is not fetching me the value for the specific field
Thanks...
-
Monday, April 30, 2012 9:09 AMModerator
Hi,
I not sure why you want to use service in your plugin, you should get data using iorganiztion object instead of service.
also you code is not correct, you are using retrieve so it will only return one entity not entity collection
use need to use like below
_lead = (Entity)service.Retrieve("lead", ID, new ColumnSet(new string[] {"firstname", "lastname" })); // ID is a existing leadid
Mahain : Check My Blog
Follow me on Twitter
Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.- Proposed As Answer by Mahender PalMVP, Moderator Monday, April 30, 2012 9:09 AM

