2015-11-03 75 views
0

我用下面的方式創建組織服務代理對象無驗證錯誤:OrganizationServiceProxy:當錯誤的密碼是設置

[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,用戶名,密碼和域,一切工作作爲exp ected。但是,如果設置了錯誤的密碼,則按照以下方式,服務根本無響應。它沒有發生任何事情。

EntityCollection res = OrgServiceProxy.RetrieveMultiple(query); 

當然,我期待身份驗證失敗的錯誤。任何建議,我在這裏失蹤?

提前致謝!

+0

至少應該有一個超時。沒有異常產生? – Daryl

+0

我試圖將超時設置爲5秒。一樣。沒有得到任何例外。這很奇怪。 – lazarus

+0

我假設你正在通過並調試它?或者你只是在運行它並檢查某種日誌? – Daryl

回答

0

我解決了這個問題與添加GetServiceProxy下面方法 - 時創建ClientCredentials

clientCreds.SupportInteractive = false; 

我想通了這一點後,我在控制檯應用程序移動整個邏輯。當錯誤的密碼設置和應用程序處於調試模式,我得到Windows登錄提示。然後我發現this answer