In CRM Web Services if you are making some changes in CRM Entities they will not get reflected until you will not update the Web Reference but In case of Dynamic Entity Class they will get effected immediately.
Please refer the following code :-
Lead Creation through CRM Web Service
Note : Please add you web reference first
Note : Please add you web reference first
=========================================
using System;
using System.Collections.Generic;
using System.Text;
using TestCRM.CrmSdk;
namespace TestCRM
{
class Program
{
static void Main(string[] args)
{
CrmAuthenticationToken token = new CrmAuthenticationToken();
token.AuthenticationType = 0;
token.OrganizationName = "AdventureWorksCycle";
CrmService svb = new CrmService();
svb.CrmAuthenticationTokenValue = token;
svb.Credentials = System.Net.CredentialCache.DefaultCredentials;
//svb.Url = "http://crm/mscrmservices/2007/crmservice.asmx";
lead l = new lead();
l.subject = "From Normal Code";
l.lastname = "Singh";
l.firstname = "Kuldeep";
l.companyname = "Koenig";
Guid id = svb.Create(l);
Console.WriteLine("Created");
Console.ReadLine();
}
}
}
Lead Creation through CRM DLL’s
Note : Please Add you DLL references first
Note : Please Add you DLL references first
===========================================
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Crm.Sdk;
using Microsoft.Crm.SdkTypeProxy;
namespace Ch4_61_Example
{
class Program
{
void abc()
{
CrmService svc=new CrmService();
CrmAuthenticationToken token=new CrmAuthenticationToken();
token.AuthenticationType=0;
token.OrganizationName="AdventureWorksCycle";
svc.CrmAuthenticationTokenValue=token;
svc.Credentials=System.Net.CredentialCache.DefaultCredentials;
DynamicEntity dyn = new DynamicEntity();
dyn.Name = "lead";
dyn.Properties.Add(CreateStringProperty("subject","New Lead using Dynamic Entity Class"));
dyn.Properties.Add(CreateStringProperty("lastname", "Jones"));
dyn.Properties.Add(CreateStringProperty("firstname", "Devi"));
dyn.Properties.Add(CreateStringProperty("companyname", "Koenig"));
dyn.Properties.Add(CreateStringProperty("salutation", "Dear,"));
dyn.Properties.Add(CreateStringProperty("new_description", "Test dll"));
TargetCreateDynamic target = new TargetCreateDynamic();
target.Entity = dyn;
CreateRequest req = new CreateRequest();
req.Target = target;
CreateResponse res = (CreateResponse)svc.Execute(req);
Console.WriteLine("Created");
}
static void Main(string[] args)
{
new Program().abc();
Console.ReadLine();
}
private Property CreateStringProperty(string Name, string Value)
{
StringProperty prop = new StringProperty();
prop.Name = Name;
prop.Value = Value;
return prop;
}
}
}
No comments:
Post a Comment