2017-02-13 9 views
1

Dynamics 365オンライン組織に接続する次のコードがあります。 orgService.Execute(new WhoAmIRequest());にヌル参照例外がスローされ、エラーログはコードの下にあります。私は、異なるコンソールアプリケーションを持つ2つのマシンでこれを試しました。私は8.2と8.0 SDK DLLの両方を試しました。私がと7.x SDK DLLを使用してこれを書き直すと、すべて正常に動作します。私は、同じ資格情報を使用して組織に閲覧す​​ることができます(&がタイプミスがないことを確認するために貼り付けられたカット。)CrmServiceClientは常にnullを返す組織サービス

接続文字列の形式はhttps://msdn.microsoft.com/en-us/library/mt608573.aspxでの例から取られる:

という名前のアカウントのOfficeを使用して365

<add name="MyCRMServer" -connectionString="AuthType=Office365;[email protected]; Password=passcode;Url=https://contoso.crm.dynamics.com"/>

基本的なコード。

var connectionString = @"Url=https://ORGNAME.crm.dynamics.com; [email protected]; Password=43JF##$j#@Ha; Authype=Office365;"; 

var client = new CrmServiceClient(connectionString);    

var orgService = (IOrganizationService)client.OrganizationWebProxyClient ?? client.OrganizationServiceProxy; 

orgService.Execute(new WhoAmIRequest()); 

エラーログ出力:

Microsoft.Xrm.Tooling.Connector.CrmServiceClient Information: 8 : Discovery URI is = https://ORGNAME.crm.dynamics.com:443/XRMServices/2011/Discovery.svc 
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Information: 8 : DiscoverOrganizations - Initializing Discovery Server Object with https://ORGNAME.crm.dynamics.com/XRMServices/2011/Discovery.svc 
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Verbose: 16 : DiscoverOrganizations - attempting to connect to CRM server @ https://ORGNAME.crm.dynamics.com/XRMServices/2011/Discovery.svc 
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Error: 2 : Source : System.ServiceModel 
Method : Retrieve 
Date : 2/13/2017 
Time : 5:42:37 PM 
Error : Metadata contains a reference that cannot be resolved: 'https://ORGNAME.crm.dynamics.com/_common/error/errorhandler.aspx?BackUri=&ErrorCode=&Parm0=%0d%0a%0d%0aتفاصيل الخطأ: The service '%2fXRMServices%2f2011%2fDiscovery.svc' cannot be activated due to an exception during compilation. The exception message is: Could not load file or assembly 'Microsoft.Crm.Site.Services%2c Version%3d8.0.0.0%2c Culture%3dneutral%2c PublicKeyToken%3d31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..&RequestUri=%2fXRMServices%2f2011%2fDiscovery.svc%3fwsdl%26sdkversion%3d8.1&user_lcid=1025'. 
Stack Trace : at System.ServiceModel.Description.MetadataExchangeClient.MetadataRetriever.Retrieve(TimeoutHelper timeoutHelper) 
    at System.ServiceModel.Description.MetadataExchangeClient.ResolveNext(ResolveCallState resolveCallState) 
    at System.ServiceModel.Description.MetadataExchangeClient.GetMetadata(MetadataRetriever retriever) 
    at System.ServiceModel.Description.MetadataExchangeClient.GetMetadata(Uri address, MetadataExchangeClientMode mode) 
    at Microsoft.Xrm.Sdk.Client.ServiceMetadataUtility.RetrieveServiceEndpointMetadata(Type contractType, Uri serviceUri, Boolean checkForSecondary) 
    at Microsoft.Xrm.Sdk.Client.ServiceConfiguration`1..ctor(Uri serviceUri, Boolean checkForSecondary) 
    at Microsoft.Xrm.Sdk.Client.ServiceConfigurationFactory.CreateManagement[TService](Uri serviceUri, Boolean enableProxyTypes, Assembly assembly) 
    at Microsoft.Xrm.Sdk.Client.ServiceConfigurationFactory.CreateManagement[TService](Uri serviceUri) 
    at Microsoft.Xrm.Tooling.Connector.CrmWebSvc.CreateAndAuthenticateProxy[T](IServiceManagement`1 servicecfg, Uri ServiceUri, Uri homeRealm, ClientCredentials userCredentials, ClientCredentials deviceCredentials, String LogString) 
    at Microsoft.Xrm.Tooling.Connector.CrmWebSvc.DiscoverOrganizations(Uri discoveryServiceUri, Uri homeRealmUri, ClientCredentials clientCredentials, ClientCredentials deviceCredentials) 
    at Microsoft.Xrm.Tooling.Connector.CrmWebSvc.DiscoverOrganizations(Uri discoveryServiceUri, Uri homeRealmUri, NetworkCredential networkCredential) 
    at Microsoft.Xrm.Tooling.Connector.CrmWebSvc.InitCRM2011Service() 
====================================================================================================================== 
Inner Exception Level 1 : 
Source : System.Runtime.Serialization 
Method : ThrowXmlException 
Date : 2/13/2017 
Time : 5:42:37 PM 
Error : CData elements not valid at top level of an XML document. Line 1, position 3. 
Stack Trace : at System.Xml.XmlExceptionHelper.ThrowXmlException(XmlDictionaryReader reader, XmlException exception) 
    at System.Xml.XmlUTF8TextReader.Read() 
    at System.ServiceModel.Description.MetadataExchangeClient.MetadataLocationRetriever.GetXmlReader(HttpWebResponse response, Int64 maxMessageSize, XmlDictionaryReaderQuotas readerQuotas) 
    at System.ServiceModel.Description.MetadataExchangeClient.MetadataLocationRetriever.DownloadMetadata(TimeoutHelper timeoutHelper) 
    at System.ServiceModel.Description.MetadataExchangeClient.MetadataRetriever.Retrieve(TimeoutHelper timeoutHelper) 
====================================================================================================================== 

Microsoft.Xrm.Tooling.Connector.CrmServiceClient Error: 2 : Unable to Login to Dynamics CRM 
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Error: 2 : OrganizationWebProxyClient is null 
Microsoft.Xrm.Tooling.Connector.CrmServiceClient Error: 2 : OrganizationServiceProxy is null 

答えて

2

あなたは、接続文字列の代わりにCrmServiceClientに直接パラメータを渡す試したことがありますか?

私はこの次のような方法

public CrmServiceClient(string crmUserId, SecureString crmPassword, string crmRegion, string orgName, bool useUniqueInstance = false, bool useSsl = false, OrganizationDetail orgDetail = null, bool isOffice365 = false); 

を使用してDynamics365に正常に接続し、ここで私は

var pwd = ConvertToSecureString("userpassword"); 
CrmServiceClient client = new CrmServiceClient("[email protected]", pwd, "NorthAmerica", "orgname", isOffice365: true); 

を適用して、ここで文字列に

private System.Security.SecureString ConvertToSecureString(string password) 
{ 
    if (password == null) 
     throw new ArgumentNullException("missing pwd"); 

    var securePassword = new System.Security.SecureString(); 
    foreach (char c in password) 
     securePassword.AppendChar(c); 

    securePassword.MakeReadOnly(); 
    return securePassword; 
} 
を確保するためにパスワードを変換する方法です方法を説明しますすることができます
+0

その方法は確かに動作します、それを投稿していただきありがとうございます。 SDKで説明されている接続文字列メソッドが機能しない理由は解決されません。私は何かが間違っているのか、それともバグなのか判断しようとしています。問題は私の実際のアプリケーションでは、設定ファイルから接続文字列を取得する方が好きです。これにより、接続のタイプを特定して正しいパラメータを渡す必要がなくなります。 – Nicknow

+0

私はそれを理解しました。私は 'connectionString'に型を持っています。それは__authtype__されている必要があり、私は__authype__を持っています。つまり、あなたの答えは実際に私をそこに連れてきて、信用を得なければならない - 明示的なパラメータとして認証タイプを宣言することは、この問題を解消するのに役立ちます。 – Nicknow

+0

あなたは根本的な原因を見つけることができてうれしく思っています:) .. btwは、最初のインスタンスのLOLで気付きにくいタイプミスでした。 –

関連する問題