web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / Nishant Rana’s Weblog / Creating a simple Callout i...

Creating a simple Callout in Microsoft Dynamics CRM 3.0

Nishant Rana Profile Picture Nishant Rana 11,325 Microsoft Employee
Create a class library project in Visual Studio 2003.
 
Add reference to the following assembly Microsoft.Crm.Platform.Callout.Base.dll.
 
Inherit the Microsoft.Crm.Callout.CrmCalloutBase class.
 
Now override the event against which you want to put your business logic.
 
 
Add web reference to CrmService
http://servername:port/mscrmservices/2006/crmservice.asmx
 
Set up the CrmService properties like url, credentials and CallerIdValue
 
CrmService service = new CrmService();
            service.Url = “http://servername: port /mscrmservices/2006/CrmServiceWsdl.aspx”;
            service.Credentials = System.Net.CredentialCache.DefaultCredentials;
            service.CallerIdValue = new CallerId();           
            service.CallerIdValue.CallerGuid = userContext.UserId;
 
For our PostUpdate event handler we can see that the values for preImageEntityXml as well as postImageEntityXml are passed as a string which essentialy is a xml.
 
public override void PostUpdate(
                                                CalloutUserContext  userContext,
                                                CalloutEntityContext  entityContext,
                                                string  preImageEntityXml,
                                                string  postImageEntityXml
                                                )
 
So first we will convert it into a dynamic entity
 
DynamicEntity entityPost=ConvertToDynamicEntity(postImageEntityXml);
 
The definition of the ConvertToDynamicEntity function is
 
private static DynamicEntity ConvertToDynamicEntity(string xml)
                                {
 
                                                TextReader sr = new StringReader(xml);
 
                                                XmlRootAttribute root = new XmlRootAttribute(“BusinessEntity”);
                                                root.Namespace = http://schemas.microsoft.com/crm/2006/WebServices”;
                                               
 
                                                XmlSerializer xmlSerializer = new XmlSerializer(typeof(BusinessEntity), root);
                                                BusinessEntity entity = (BusinessEntity)xmlSerializer.Deserialize(sr);
 
                                                return (DynamicEntity) entity;
                                }
 
We’ll deserialize the xml output to get an instance of DynamicEntity.
 
To make it more easy to work with the properties we can make use of the following class PropertiyDictionary in our callout.
 
 
 
We’ll pass the instance of the newly created dynamic entity to the PropertyDictionary’s constructor.
 
PropertyDictionary properties=new PropertyDictionary(entityPost);
 
Now to work with properties we can do something like this
 
// For CrmDateTimeProperty
            if (properties.Contains(“actualclosedate”))
            {
                CrmDateTimeProperty acd = (CrmDateTimeProperty)properties[“actualclosedate”];
                actualclosedate = acd.Value;
            }
 
            // For CrmMoneyProperty
            if (properties.Contains(“new_estimatedrevenue”))
            {
 
                CrmMoneyProperty ner = (CrmMoneyProperty)properties[“new_estimatedrevenue”];
                new_estimatedrevenue = ner.Value;
            }
            // For PicklistProperty
            if (properties.Contains(“salesstagecode”))
            {
 
 
                PicklistProperty salesstagecode = (PicklistProperty)properties[“salesstagecode”];               
                salesstage = salesstagecode.Value.Value.ToString();
            }
           
 
That’s it…


This was originally posted here.

Comments

*This post is locked for comments