using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Tooling.Connector;
using System;
using System.ServiceModel;
using System.Threading;namespace LuoYongLab
{
class Program
{
static void Main(string[] args)
{
try
{
for (var i = 0; i < 5; i++)
{
ThreadStart tStart = new ThreadStart(Work);
Thread thread = new Thread(tStart);
thread.Start();
}
Console.WriteLine("程序运行完成!");
Console.ReadKey();
}
catch (FaultException ex)
{
Console.WriteLine("程序出现异常:ex.Message=" + ex.Message);
Console.ReadKey();
}
}static void Work()
{
Console.WriteLine("线程开始" + DateTime.Now.ToLongTimeString() + ";线程ID:" + Thread.CurrentThread.ManagedThreadId);
var crmSvc = new CrmServiceClient(new System.Net.NetworkCredential("crmadmin@luoyong.me", "Pass", null), Microsoft.Xrm.Tooling.Connector.AuthenticationType.IFD, "demo.luoyong.me", "443", "demo", useUniqueInstance: false, useSsl: true);
Console.WriteLine("线程ID: " + Thread.CurrentThread.ManagedThreadId + ";Token过期时间:" + crmSvc.OrganizationServiceProxy.SecurityTokenResponse.Response.Lifetime.Expires);
if (crmSvc.IsReady)
{
QueryExpression qe = new QueryExpression("organization");
qe.ColumnSet = new ColumnSet("languagecode", "basecurrencyid");
EntityCollection ec = crmSvc.RetrieveMultiple(qe);
if (ec.Entities.Count >= 1)
{
Console.WriteLine("线程ID: " + Thread.CurrentThread.ManagedThreadId + ";组织偏好语言:" + ec.Entities[0].GetAttributeValue<int>("languagecode"));
}
}
Console.WriteLine("线程结束" + DateTime.Now.ToLongTimeString() + ";线程ID:" + Thread.CurrentThread.ManagedThreadId);
}
}
}
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Xrm.Sdk.Query;
using System;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.Threading;namespace LuoYongLab
{
class Program
{
public static IServiceManagement<IOrganizationService> sm;
static void Main(string[] args)
{
sm = ServiceConfigurationFactory.CreateManagement<IOrganizationService>(new Uri("https://demo.luoyong.me/XRMServices/2011/Organization.svc"));
try
{
for (var i = 0; i < 5; i++)
{
ThreadStart tStart = new ThreadStart(Work);
Thread thread = new Thread(tStart);
thread.Start();
}
Console.WriteLine("程序运行完成!");
Console.ReadKey();
}
catch (FaultException ex)
{
Console.WriteLine("程序出现异常:ex.Message=" + ex.Message);
Console.ReadKey();
}
}static void Work()
{
ClientCredentials credentials = new ClientCredentials();
credentials.UserName.UserName = "crmadmin@luoyong.me";
credentials.UserName.Password = "Pass";
Console.WriteLine("线程开始" + DateTime.Now.ToLongTimeString() + ";线程ID:" + Thread.CurrentThread.ManagedThreadId);
OrganizationServiceProxy orgSvc = new OrganizationServiceProxy(sm, credentials);
QueryExpression qe = new QueryExpression("organization");
qe.ColumnSet = new ColumnSet("languagecode", "basecurrencyid");
EntityCollection ec = orgSvc.RetrieveMultiple(qe);
if (ec.Entities.Count >= 1)
{
Console.WriteLine("线程ID: " + Thread.CurrentThread.ManagedThreadId + ";组织偏好语言:" + ec.Entities[0].GetAttributeValue<int>("languagecode"));
}
Console.WriteLine("线程结束" + DateTime.Now.ToLongTimeString() + ";线程ID:" + Thread.CurrentThread.ManagedThreadId);
}
}
}
评论