How to generate CRM organization service using service proxy ?
This is my new post to generate organization service in CRM 2013,2015 and 2016. Simplest method to generate dynamics CRM organization service,you can use below code for creting crm organisation service. For this you need to follow below instructions.
For generation organization service below assemblies are required.
Add below code in .cs file and App config file respectively.
- Microsoft.Xrm.Sdk.dll
- Microsoft.Crm.Sdk.Proxy.dll
- System.configuration
- System.ServiceModel
- using Microsoft.Crm.Sdk.Messages;
- using Microsoft.Xrm.Sdk;
- using Microsoft.Xrm.Sdk.Client;
- using System.ServiceModel.Description;
Add below code in .cs file and App config file respectively.
//.CS File Code
public static IOrganizationService GetCRMService()
{
try
{
// Get Ogranization Service Url
Uri oUri = new Uri(System.Configuration.ConfigurationManager.AppSettings["OrganizationUrl"]);
//Your credentials
ClientCredentials clientCredentials = new ClientCredentials();
clientCredentials.UserName.UserName = System.Configuration.ConfigurationManager.AppSettings["Username"];
clientCredentials.UserName.Password = System.Configuration.ConfigurationManager.AppSettings["Password"];
//Create your Organization Service Proxy
OrganizationServiceProxy _serviceProxy = new OrganizationServiceProxy(
oUri,
null,
clientCredentials,
null);
_serviceProxy.EnableProxyTypes();
IOrganizationService service = _serviceProxy;
// Obtain information about the logged on user from the web service.
Guid userId = ((WhoAmIResponse)_serviceProxy.Execute(new WhoAmIRequest())).UserId;
if (userId != null)
{ return service; }
else
{ return null; }
}
catch (Exception)
{
return null;
}
}
//App config file code
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<!--Organization Service Endpoint Address-->
<add key="OrganizationUrl" value="https://your organisation/XRMServices/2011/Organization.svc" />
<!--UserName with domain-->
<add key="Username" value="username" />
<!--password-->
<add key="Password" value="password" />
</appSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Xrm.Sdk" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Enjoy the great technology Dynamics CRM. Good luck.....!!!!!
Please feel free to put comments for your queries.Thanks.
No comments:
Post a Comment