【发布时间】:2015-11-05 16:42:27
【问题描述】:
我正在使用以下方式创建组织服务代理对象:
[ThreadStatic]
public static OrganizationServiceProxy OrgServiceProxy;
// ...
sLog.DebugFormat("Get AuthenticationProviderType...");
AuthenticationProviderType _crmAuthType = this.GetServerType(parameters.DiscoveryUri);
sLog.DebugFormat("Get AuthenticationProviderType - DONE!");
// ...
sLog.Info("Perform metadata download (ServiceConfigurationFactory.CreateConfiguration)...");
IServiceConfiguration<IOrganizationService> _crmServiceConfiguration = ServiceConfigurationFactory.CreateConfiguration<IOrganizationService>(parameters.OrgServiceUri);
sLog.Info("Perform metadata download (ServiceConfigurationFactory.CreateConfiguration) - DONE");
// ...
// enable proxy types
var behavior = new ProxyTypesBehavior() as IEndpointBehavior;
behavior.ApplyClientBehavior(_crmServiceConfiguration.CurrentServiceEndpoint, null);
// ...
public OrganizationServiceProxy GetServiceProxy(ICRMConnectionParameters parameters)
{
// ...
ClientCredentials clientCreds = new ClientCredentials();
clientCreds.Windows.ClientCredential.UserName = parameters.UserName;
clientCreds.Windows.ClientCredential.Password = parameters.Password;
clientCreds.Windows.ClientCredential.Domain = parameters.Domain;
sLog.DebugFormat("Setup client proxy...");
OrgServiceProxy = new OrganizationServiceProxy(_crmServiceConfiguration, clientCreds);
sLog.DebugFormat("Setup client proxy - DONE.");
return OrgServiceProxy;
}
这里只需注意 AuthenticationProviderType 和 IServiceConfiguration 是静态缓存的。上面的代码是名为 CRMConnection 的类的一部分。
我还有一个包含以下属性的抽象类(ProxyUser):
private CRMConnection conn;
// ...
protected OrganizationServiceProxy OrgServiceProxy
{
get
{
//return orgService;
return this.Conn.GetServiceProxy();
}
}
protected CRMConnection Conn
{
get
{
conn = conn ?? new CRMConnection();
return conn;
}
}
在另一个继承 ProxyUser 的类中,我有以下代码的方法:
ColumnSet columnSet = new ColumnSet();
ConditionExpression condition1 = new ConditionExpression("new_id", ConditionOperator.NotNull);
FilterExpression filter = new FilterExpression(LogicalOperator.And);
filter.AddCondition(condition1);
QueryExpression query = new QueryExpression()
{
EntityName = new_brand.EntityLogicalName,
ColumnSet = columnSet,
Criteria = filter,
NoLock = true
};
EntityCollection res = OrgServiceProxy.RetrieveMultiple(query);
现在我们进入正题:)
如果我设置了正确的参数——组织服务 url、发现服务 url、用户名、密码和域,一切都会按预期工作。但是,如果设置了错误的密码,在下面的行中,服务根本没有响应。它不会发生任何事情。
EntityCollection res = OrgServiceProxy.RetrieveMultiple(query);
当然,我期待身份验证失败错误。有什么我在这里缺少的建议吗?
提前致谢!
【问题讨论】:
-
至少应该有一个超时。没有产生异常?
-
我尝试将超时设置为 5 秒。一样。没有得到任何异常。这很奇怪。
-
我假设您正在逐步调试它?还是您只是运行它并检查某种日志?
-
两者。在调试器中,涉及到行“OrgServiceProxy.RetrieveMultiple(query);”并留在那里。 OrgSerivceProxy 已创建,但没有任何反应。
-
我会尝试 WhoAmIRequest 看看是否有什么不同。
标签: dynamics-crm-2011 dynamics-crm