FetchXML is query language based on a schema that describes the capabilities of the language. The FetchXML language supports similar query capabilities as query expression. It is used primarily as a serialized form of query expression, used to save a query as a user owned saved view in the userquery entity or as an organization owned view in the savedquery entity. A FetchXML query can be executed by using the Fetch method. There are also messages to convert between query expression and FetchXML.
Generally, the RetrieveMultiple method performs faster than the Fetch method because it does not have to parse the query.
// Set up the CRM Service. CrmAuthenticationToken token = new CrmAuthenticationToken(); token.AuthenticationType = 0; token.OrganizationName = "CRMHUNT"; CrmService service = new CrmService(); service.Url = ""http://<servername>:<port>/mscrmservices/2007/crmservice.asmx"; service.CrmAuthenticationTokenValue = token; service.Credentials = System.Net.CredentialCache.DefaultCredentials; // Retrieve all accounts. // Be aware that using all-attributes may adversely affect performance // and cause unwanted cascading in subsequent updates. // A best practice is to retrieve the least amount of data required. string fetch1 = "<fetch mapping='logical'>"; fetch1 += "<entity name='account'><all-attributes/>"; fetch1 += "</entity></fetch>"; // Fetch the results. String result1 = service.Fetch(fetch1); // Retrieve all accounts owned by the user who has read access rights to the accounts and // where the last name of the user is not HUNT. string fetch2 = @" <fetch mapping='logical'> <entity name='account'> <attribute name='accountid'/> <attribute name='name'/> <link-entity name='systemuser' to='owninguser'> <filter type='and'> <condition attribute='lastname' operator='ne' value='HUNT' /> </filter> </link-entity> </entity> </fetch> "; // Fetch the results. String result2 = service.Fetch(fetch2);