How To Connect Crm 2007 c#
6:27 PMMicrosoft Dynamic CRM 4.0 |
- config file
- I usualy create new class for crm connection function, retrieve entity etc.
- main program
<?xml version="1.0" encoding="utf-8"?> <configuration> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/> </startup> <appSettings> <add key="CRMServerURL" value="http://{{your crm address}}/MSCRMServices/2007/crmservice.asmx?wsdl"/> <add key="CRMOrganization" value="yourorganization"/> <add key="CRMUsername" value="yuorusername"/> <add key="CRMPassword" value="yourpasword"/> <add key="CRMDomain" value="yourdomain"/> </appSettings> </configuration>
using Microsoft.Crm.Sdk; using Microsoft.Crm.Sdk.Query; using Microsoft.Crm.SdkTypeProxy; using Microsoft.Crm.Sdk.Metadata; using Microsoft.Crm.SdkTypeProxy.Metadata; using System; using System.Collections.Generic; using System.Configuration; using System.Linq; using System.Net; using System.Text; using System.Threading.Tasks; using System.IO; using System.Xml; namespace CRMTutorial { class CRMClass { string _crmserviceurl = ConfigurationManager.AppSettings["CRMServerURL"]; string _organization = ConfigurationManager.AppSettings["CRMOrganization"]; string _username = ConfigurationManager.AppSettings["CRMUsername"]; string _password = ConfigurationManager.AppSettings["CRMPassword"]; string _domain = ConfigurationManager.AppSettings["CRMDomain"]; public CrmService crmservice_conn() { CrmAuthenticationToken mytoken = new CrmAuthenticationToken(); mytoken.AuthenticationType = 0; mytoken.OrganizationName = this._organization; NetworkCredential mycredential = new NetworkCredential(); mycredential.UserName = this._username; mycredential.Password = this._password; mycredential.Domain = this._domain; CrmService myservice = new CrmService(); myservice.Url = _crmserviceurl; myservice.UseDefaultCredentials = false; myservice.CrmAuthenticationTokenValue = mytoken; myservice.Credentials = mycredential; return myservice; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.Crm.Sdk; using Microsoft.Crm.Sdk.Query; using Microsoft.Crm.SdkTypeProxy; using Microsoft.Crm.Sdk.Metadata; using Microsoft.Crm.SdkTypeProxy.Metadata; using System.IO; using System.Xml.Linq; using System.Xml; using System.Configuration; namespace CRMTutorial { class Program { static void Main(string[] args) { CRMClass crmclass = new CRMClass(); //call service you have created CrmService service = crmclass.crmservice_conn(); /* *your code here */ } } }
happy coding :)
0 comments