First, by creating an ASP.NET project (WebForms or MVC 3), add the following links:
- Microsoft.crm.sdk.proxy.
- Microsoft.xrm.sdk.
- System.Runtime Serialization
- System.ServiceModel.
In your code to create the class, then add the following code:
private IOrganizationService GetCrmService(string userName, string password, string domain, Uri serviceUri)
{
OrganizationServiceProxy _serviceProxy;
ClientCredentials credentials = new ClientCredentials();
credentials.Windows.ClientCredential = new System.Net.NetworkCredential(userName, password, domain);
ClientCredentials deviceCredentials = new ClientCredentials();
using (_serviceProxy = new OrganizationServiceProxy(serviceUri,
null,
credentials,
deviceCredentials))
{
_serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());
return (IOrganizationService)_serviceProxy;
}
}
If you want to get multiple entries:
string fetch = @"My Fetch goes here";
EntityCollection records = getCrmService().RetrieveMultiple(new FetchExpression(fetch));
I highly recommend downloading the SDK or checking out this.
You will find many examples and walkthroughs to help you build good portals.
source
share