Reputation: 323
Try to debug my console app from yesterday but no success. My script keep throwing:
Metadata contains a reference that cannot be resolved: 'https://xxxxxxx/XRMServices/2011/Organization.svc?wsdl&sdkversion=8.2'.
xxxxxxx is place holder for my crm domain.
I m using Dynamics 365 on premise version 1612(8.2.0.749)(DB 8.2.0.749). The Dynamics 365 was IFD.
To create console app, I already,
1) Using latest dynamics 365 Sdk version 8.2.1.1 Microsoft Dynamics 365 SDK
2) Yeah, also install this sdk into my GAC. Then reboot my server.
3) To check wether my organization service endpoint is correct, I also paste my OrganizationService endpoint address https://xxxxxxx/XRMServices/2011/Organization.svc
in browser and its working by return the service.**
4) I m using Visual studio 2013, .net framework 4.5.2
weird things when using Dynamics 365 online trial its working fine.
This is my sample code:
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);
}
Details:
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:
Thanks in advance.
Upvotes: 0
Views: 4236
Reputation: 323
This problem occurs when the client computer cannot send an HTTP request. The client computer cannot send the HTTP request because the connection has been closed or is unavailable. And Today I realize that My DB server was using TLS1.2
not SSL
as a protocol to connect to CRM App Server, so when making a connection from DB to CRM via console app
, I must explicitly set the TLS version on the ServicePointManager. Just have this code run anytime before you make the call to CRM organization service.
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
Hope this will benefit someone in future.
Upvotes: 1
Reputation: 145
We have used IServiceManagement for crm version 2011 and upwards. An example in F# is shown below - which translates almost directly into 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
Upvotes: 0
Reputation: 4283
When I upgraded an application to CRM365, I had to change the way a connection was made. This is what I'm using
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);
This is not on premise, so I'm not positive it will work. But the connection string must specify the AuthType, and you need to use the CrmServiceClient for the connection.
Upvotes: 1