0

尝试从昨天开始调试我的控制台应用程序,但没有成功。我的脚本不断抛出:

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

xxxxxxx 是我的 crm 域的占位符。

我在本地版本 1612(8.2.0.749)(DB 8.2.0.749) 上使用 Dynamics 365。Dynamics 365 是 IFD。

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

1) 使用最新的dynamics 365 Sdk 版本8.2.1.1 Microsoft Dynamics 365 SDK

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

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

4)我正在使用 Visual Studio 2013,.net 框架 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);

        }

异常抛出: 异常抛出:

细节:

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: 

提前致谢。

4

3 回答 3

1

当我将应用程序升级到 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 进行连接。

于 2017-10-12T14:20:37.623 回答
1

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

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12

希望这将对将来的某人有所帮助。

于 2017-10-19T12:58:26.040 回答
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
于 2017-10-13T06:50:13.933 回答