Показать сообщение отдельно
Старый 04.02.2012, 15:33   #5  
Aliwer is offline
Aliwer
Участник
 
14 / 11 (1) +
Регистрация: 26.12.2011
X++:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel.Description;
using System.Net;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Xrm.Sdk;

namespace ViewsConsole
{
    class Program
    {
        static void Main(string[] args)
        {
           // string ms = "Bob Train";
            ClientCredentials Credentials = new ClientCredentials();
            Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
            //This URL needs to be updated to match the servername and Organization for the environment.
            Uri OrganizationUri = new Uri("http://192.168.55.71:5555/dfnts/XRMServices/2011/Organization.svc");
            Uri HomeRealmUri = null;
            using (Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy serviceProxy = new Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy(OrganizationUri, HomeRealmUri, Credentials, null))
            {
                serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());
                IOrganizationService service = (IOrganizationService)serviceProxy;
                //fetch example
                string contactt = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
                                  <entity name='account'>
                                  <attribute name='name' />
                                  <attribute name='primarycontactid' />
                                  <attribute name='telephone1' />
                                  <attribute name='accountid' />
                                  <order attribute='name' descending='false' />
                                  <filter type='and'>
                                  <condition attribute='name' operator='not-null' />
                                  </filter>
                                  </entity>
                                  </fetch>";

                string fontac = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
                                  <entity name='account'>
                                  <attribute name='name' />
                                  <attribute name='primarycontactid' />
                                  <attribute name='telephone1' />
                                  <attribute name='accountid' />
                                  <order attribute='name' descending='false' />
                                  <filter type='and'>
                                  <condition attribute='accountnumber' operator='not-null' />
                                  </filter>
                                  </entity>
                                  </fetch>";

                EntityCollection result = service.RetrieveMultiple(new Microsoft.Xrm.Sdk.Query.FetchExpression(contactt));
                EntityCollection fesuld = service.RetrieveMultiple(new Microsoft.Xrm.Sdk.Query.FetchExpression(fontac));
                foreach (var c in result.Entities)
                {
                    Console.WriteLine("----------");
                    System.Console.WriteLine(c.Attributes["name"]);
                }
               
                    foreach (var s in fesuld.Entities)
                    System.Console.WriteLine(s.Attributes["name"]);
                
                Console.ReadLine();
               
                //end fetch example}

               // if (contactt == fontac) Console.WriteLine("KRUTO");
                //else Console.WriteLine("NeKruto");
                
                    
                
                //This code will clear the textboxes after the contact is created.
            }
        }
    }
}