using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Crm.Sdk;
using Microsoft.Crm.SdkTypeProxy;
using Microsoft.Crm.Sdk.Query;
using Microsoft.Crm.Sdk.Metadata;
using Microsoft.Crm.SdkTypeProxy.Metadata;
namespace UserEntity
{
public class Main:IPlugin
{
#region IPlugin 成员
public void Execute(IPluginExecutionContext context)
{
CrmService service = GetCrmProxyUsingEndpointUrlInChildPipeline("http://de-c179-src/MSCrmServices/2007/CrmService.asmx", context);
//userID
WhoAmIRequest userRequest = new WhoAmIRequest();
WhoAmIResponse user = (WhoAmIResponse)service.Execute(userRequest);
Guid userid = user.UserId;
// Create the column set object that indicates the properties to be retrieved.
ColumnSet cols = new ColumnSet();
cols.Attributes.Add("New_name");// = new string[] { "fullname"};
// Create the ConditionExpression.
ConditionExpression condition = new ConditionExpression();
// Set the condition for the retrieval to be when the contact's address' city is Sammamish.
condition.AttributeName = "New_ControlEntity";
condition.Operator = ConditionOperator.Equal;
condition.Values = new string[] { userid.ToString() };
// Create the QueryExpression object.
QueryExpression query = new QueryExpression();
// Set the properties of the QueryExpression object.
query.EntityName = "new_canuseentity";
query.ColumnSet = cols;
// Retrieve the New_ControlEntity.
BusinessEntityCollection newentity = service.RetrieveMultiple(query);
foreach (BusinessEntity b in newentity.BusinessEntities)
{
}
}
public static CrmService GetCrmProxyUsingEndpointUrlInChildPipeline(string endPointUrl, IPluginExecutionContext context)
{
CrmService childCrmService = new CrmService();
childCrmService.Url = endPointUrl;
childCrmService.Credentials = System.Net.CredentialCache.DefaultCredentials;
childCrmService.CrmAuthenticationTokenValue = new CrmAuthenticationToken();
childCrmService.CrmAuthenticationTokenValue.AuthenticationType = AuthenticationType.AD;
childCrmService.CrmAuthenticationTokenValue.OrganizationName = context.OrganizationName;
childCrmService.CorrelationTokenValue = new CorrelationToken(context.CorrelationId, context.Depth, context.CorrelationUpdatedTime);
return childCrmService;
}
#endregion
}
}
我现在需要在Plugin中查询一个自定义的信息,因为我注册时是publish事件,所以只能用webservice,请问我查询那一步 foreach里面怎么获得属性的信息,系统实体我会!
梅小虎