MS CRm 2011 Retrieve entity Meta Data Using SOAP Service in SilverLight

MS CRm 2011 Retrieve entity Meta Data Using SOAP Service in SilverLight

Follow Below link to Add Classes to your Project “SilverlightUtility.cs” and “SilverlightExtensionMethods.cs”

http://msdn.microsoft.com/en-us/library/gg594452.aspx

using System;

using System.Collections.Generic;

using System.Linq;

using System.Net;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Animation;

using System.Windows.Shapes;

using MsCrmSoapService.CrmSdk;

using System.Text;

namespace MsCrmSoapService

{

public partial class MainPage : UserControl

{

public MainPage()

{

InitializeComponent();

}

int MaxRecordsToReturn = 5;

private void AccountList_ClickCallback(IAsyncResult result)

{

try

{

OrganizationResponse response = ((IOrganizationService)result.AsyncState).EndExecute(result);

EntityCollection results = (EntityCollection)response[“EntityCollection”];

StringBuilder sb = new StringBuilder();

if (results.Entities.Count == 0)

{

sb.AppendLine(“There are no Account records in the system.”); }

foreach (Entity entity in results.Entities)

{

// sb.AppendLine(“Account Name = ” + entity.GetAttributeValue<string>(“name”));

}

if (results.MoreRecords)

{

sb.AppendLine(“Only the first ” + MaxRecordsToReturn + ” records were returned.”);

}

// this.ReportMessage(sb.ToString());

}

catch (Exception ex)

{

// this.ReportError(ex);

}

}

protected void getdata()

{

try

{

QueryExpression query = new QueryExpression()

{

EntityName = “account”,

ColumnSet = new ColumnSet()

{

Columns = new System.Collections.ObjectModel.ObservableCollection<string>(new string[] { “name” })

},

};

query.PageInfo = new PagingInfo { Count = MaxRecordsToReturn, PageNumber = 1, PagingCookie = null };

OrganizationRequest request = new OrganizationRequest() { RequestName = “RetrieveMultiple” };

request[“Query”] = query;

IOrganizationService service = SilverlightUtility.GetSoapService();

service.BeginExecute(request, new AsyncCallback(AccountList_ClickCallback), service);

}

catch (Exception ex)

{

// this.ReportError(ex);

}

        }

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s