Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Creating a Service for retrieving data related to a account.

(0) ShareShare
ReportReport
Posted on by 370

Hi all,

I need to create a service which will return data related to an account entity in Ms Dynamics CRM. This service will have account GUID as input parameter which will be passed by the service consumer. 

I have a rough idea of how to do this i.e 

1. creating a Asp.net web service application (.asmx)  in Visual  Studio.

2. Adding a Service Reference of CRM organization service .

3. Using the Service Reference to access the classes and methods of CRM  and perform the required operations.

however i am not sure if this is the right way to do this, or there is a better way to achieve this.

Please guide as i can't move further as i am having real tough time performing the basic operations using service reference as compared to a basic plugin where it would have been a simple task to return info based on GUID.

Thanks in advance 

Regards 

Prem

*This post is locked for comments

  • Prem27 Profile Picture
    Prem27 370 on at
    RE: Creating a Service for retrieving data related to a account.

    Thanks Alok for your support !! This gave me the idea of how to do it.

  • Verified answer
    Dynamics_Alok Profile Picture
    Dynamics_Alok 1,746 on at
    RE: Creating a Service for retrieving data related to a account.

    No worries Prem.

    You can go ahead with many ways but what i prefer normally to create a CRMHelper class and write CRM related methods including connectionToCRM using your CRM url and username etc.

    FYI

     public bool ConnectToCRMServer(string pURL, string pDomain, string pUsername, string pPassword)
            {
                IOrganizationService orgService = null;
                bool retConnectionStatus = false;
                string strConString = string.Format("Url={0}; Domain={1}; Username={2}; Password={3};", pURL, pDomain, pUsername, pPassword);
                Console.WriteLine("Connection string is Proper...");
                try
                {
                    var connection = CrmConnection.Parse(strConString);
    
                    orgService = new OrganizationService(connection);              
                   
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);                
                }
                return retConnectionStatus;
    
            }

    and then write a method to fetch Account information like this 

     public AccountInfo GetAccountDetails(Guid accountid)
            {
                AccountInfo accountInfo = null;
                try
                {
    //orgService fetched in connectToCRMServer method Entity account = orgService.Retrieve("account",accountid,new Microsoft.Xrm.Sdk.Query.ColumnSet("accountid","name",.........."What ever you want to fetch")); if(account.Contains("name")) accountInfo.Fullname = Convert.ToString(account["name"]); //And like this } catch (Exception ex) { throw; } return accountInfo; } public class AccountInfo { public string Fullname { get; set; } }


    i hope it would be helpful for you.

    Happy CRMing

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,494 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,309 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans