Dynamics 365内部部署异常元数据包含无法解析的引用:

时间:2017-10-12 14:07:17

标签: c# .net console-application dynamics-365

尝试从昨天开始调试我的控制台应用程序,但没有成功。我的剧本继续投掷:

元数据包含无法解析的引用:“https://xxxxxxx/XRMServices/2011/Organization.svc?wsdl&sdkversion=8.2”。

xxxxxxx是我的crm域名的占位符。

我使用Dynamics 365内部版本1612(8.2.0.749)(DB 8.2.0.749)。 Dynamics 365是IFD。

要创建控制台应用,我已经

1)使用最新动态365 Sdk版本8.2.1.1 Microsoft Dynamics 365 SDK

2)是的,也将此sdk安装到我的GAC中。然后重启我的服务器。

3)要检查我的组织服务端点是否正确,我还会在浏览器中粘贴我的OrganizationService端点地址https://xxxxxxx/XRMServices/2011/Organization.svc,并通过返回服务来工作。**

4)我使用Visual Studio 2013,.net framework 4.5.2

使用Dynamics 365在线试用版时,它的工作正常。

这是我的示例代码:

static void Main(string[] args)
        {

            IOrganizationService organizationservice;
            // Get the CRM connection string and connect to the CRM Organization

            ClientCredentials Credentials = new ClientCredentials();
            Credentials.UserName.UserName = "username";
            Credentials.UserName.Password = "password";

            Credentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;

            organizationservice = new OrganizationServiceProxy(
                new Uri("https://xxxxxxx/XRMServices/2011/Organization.svc"), null, Credentials, null);

        }

异常投掷: Exception throw:

详细说明:

System.InvalidOperationException was unhandled
HResult=-2146233079
Message=Metadata contains a reference that cannot be resolved: 
'https://xxxxxxx/XRMServices/2011/Organization.svc?wsdl&sdkversion=8.2'.
Source=System.ServiceModel
StackTrace:
   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.OrganizationServiceConfiguration..ctor(Uri serviceUri, Boolean enableProxyTypes, Assembly assembly)
   at Microsoft.Xrm.Sdk.Client.ServiceConfigurationFactory.CreateConfiguration[TService](Uri serviceUri, Boolean enableProxyTypes, Assembly assembly)
   at Microsoft.Xrm.Sdk.Client.ServiceConfigurationFactory.CreateConfiguration[TService](Uri serviceUri)
   at Microsoft.Xrm.Sdk.Client.ServiceProxy`1..ctor(Uri uri, Uri homeRealmUri, ClientCredentials clientCredentials, ClientCredentials deviceCredentials)
   at Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy..ctor(Uri uri, Uri homeRealmUri, ClientCredentials clientCredentials, ClientCredentials deviceCredentials)
   at ConsoleConnectToCRM.Program.Main(String[] args) in d:\CRM2015\SSIS\TestCRMConnection\TestCRMConnection\Program.cs:line 45
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()
   InnerException: System.Net.WebException
   HResult=-2146233079
   Message=The underlying connection was closed: An unexpected error occurred on a receive.
   Source=System
   StackTrace:
        at System.Net.HttpWebRequest.GetResponse()
        at System.ServiceModel.Description.MetadataExchangeClient.MetadataLocationRetriever.DownloadMetadata(TimeoutHelper timeoutHelper)
        at System.ServiceModel.Description.MetadataExchangeClient.MetadataRetriever.Retrieve(TimeoutHelper timeoutHelper)
   InnerException: System.ComponentModel.Win32Exception
        HResult=-2147467259
        Message=The client and server cannot communicate, because they do not possess a common algorithm
        Source=System
        ErrorCode=-2147467259
        NativeErrorCode=-2146893007
        StackTrace:
             at System.Net.SSPIWrapper.AcquireCredentialsHandle(SSPIInterface SecModule, String package, CredentialUse intent, SecureCredential scc)
             at System.Net.Security.SecureChannel.AcquireCredentialsHandle(CredentialUse credUsage, SecureCredential& secureCredential)
             at System.Net.Security.SecureChannel.AcquireClientCredentials(Byte[]& thumbPrint)
             at System.Net.Security.SecureChannel.GenerateToken(Byte[] input, Int32 offset, Int32 count, Byte[]& output)
             at System.Net.Security.SecureChannel.NextMessage(Byte[] incoming, Int32 offset, Int32 count)
             at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
             at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
             at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
             at System.Net.TlsStream.CallProcessAuthentication(Object state)
             at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
             at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
             at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
             at System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult result)
             at System.Net.TlsStream.Write(Byte[] buffer, Int32 offset, Int32 size)
             at System.Net.PooledStream.Write(Byte[] buffer, Int32 offset, Int32 size)
             at System.Net.ConnectStream.WriteHeaders(Boolean async)
        InnerException: 

提前致谢。

3 个答案:

答案 0 :(得分:1)

当客户端计算机无法发送HTTP请求时,会发生此问题。客户端计算机无法发送HTTP请求,因为连接已关闭或不可用。今天我意识到我的数据库服务器使用TLS1.2而不是SSL作为连接到CRM App Server的协议,因此当通过console app建立从DB到CRM的连接时,我必须明确在ServicePointManager上设置TLS版本。只需在调用CRM组织服务之前随时运行此代码。

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12

希望将来有人会受益。

答案 1 :(得分:0)

当我将应用程序升级到CRM365时,我不得不改变连接的方式。这就是我正在使用的

string crmConnectionString = $@"Url=https://<domain>;
    AuthType=Office365;
    UserName=<username>;
    Password=" + <password>;
CrmServiceClient crmSvcClient = new CrmServiceClient(crmConnectionString);
OrganizationServiceProxy proxy = crmSvcClient.OrganizationServiceProxy;
proxy.EnableProxyTypes();
OrganizationServiceContext orgContext = new OrganizationServiceContext(proxy);

这不是一个前提,所以我不肯定它会起作用。但是连接字符串必须指定AuthType,并且您需要使用CrmServiceClient进行连接。

答案 2 :(得分:0)

我们已将IServiceManagement用于crm版本2011及更高版本。下面显示了F#中的一个示例 - 它几乎直接转换为C#。

let authenticate uri username password domain =
  let m = ServiceConfigurationFactory.CreateManagement<IOrganizationService(uri)
  let cred = AuthenticationCredentials()
  cred.ClientCredentials.Windows.ClientCredential <- 
    new NetworkCredential(username, password, domain)
  let ac = m.Authenticate(cred)
  let proxy = new OrganizationServiceProxy(m, ac.ClientCredentials)
  proxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());
  proxy