OrganizationServiceProxy:设置错误密码时没有身份验证错误
OrganizationServiceProxy: No authentication error when wrong password is setup
我正在使用以下方式创建组织服务代理对象:
[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 的 class 的一部分。
我还有一个摘要 class (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 的 class 中,我有以下代码的方法:
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);
当然,我期待身份验证失败错误。有什么我在这里遗漏的建议吗?
提前致谢!
我通过在 GetServiceProxy 方法中添加以下行解决了这个问题 - 当创建 ClientCredentials 时:
clientCreds.SupportInteractive = false;
我在控制台应用程序中移动整个逻辑后发现了这一点。当设置了错误的密码并且应用程序处于调试模式时,我收到 windows 登录提示。然后我找到了this answer.
我正在使用以下方式创建组织服务代理对象:
[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 的 class 的一部分。
我还有一个摘要 class (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 的 class 中,我有以下代码的方法:
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);
当然,我期待身份验证失败错误。有什么我在这里遗漏的建议吗?
提前致谢!
我通过在 GetServiceProxy 方法中添加以下行解决了这个问题 - 当创建 ClientCredentials 时:
clientCreds.SupportInteractive = false;
我在控制台应用程序中移动整个逻辑后发现了这一点。当设置了错误的密码并且应用程序处于调试模式时,我收到 windows 登录提示。然后我找到了this answer.