DynamicsNode icon indicating copy to clipboard operation
DynamicsNode copied to clipboard

Error trying to connect to Server: Metadata contains a reference that cannot be resolved

Open ariskemper opened this issue 9 years ago • 15 comments

I tried your module on Linux Ubuntu 14.04 with latest Mono 4.2 calling external on premise dynamics crm 2015. When checking, if XRMServices/2011/Organization.svc?wsdl&sdkversion=7.1 is available via url, it is accessible. I get following error, when trying to access it.

Error: Error trying to connect to Server: Metadata contains a reference that cannot be resolved : http://crmsrv.example.com:5555/XRMServices/2011/Organization.svc?wsdl&sdkversion=7.1 System.InvalidOperationException: Metadata contains a reference that cannot be resolved : http://crmsrv.example.com:5555/XRMServices/2011/Organization.svc?wsdl&sdkversion=7.1 ---> System.ServiceModel.EndpointNotFoundException: System error. ---> System.Net.WebException: Error: NameResolutionFailure at System.Net.HttpWebRequest.EndGetRequestStream (IAsyncResult asyncResult) <0x4025ab40 + 0x00117> in :0 at System.ServiceModel.Channels.HttpRequestChannel+<BeginProcessRequest>c__AnonStorey1.<>m__0 (IAsyncResult r) <0x4025a730 + 0x000ae> in :0 --- End of inner exception stack trace --- at (wrapper managed-to-native) System.Object:__icall_wrapper_mono_remoting_wrapper (intptr,intptr) at (wrapper remoting-invoke) System.ServiceModel.Description.IMetadataExchange:Get (System.ServiceModel.Channels.Message) at System.ServiceModel.Description.MetadataExchangeClient.GetMetadataInternal (System.ServiceModel.EndpointAddress address, MetadataExchangeClientMode mode) <0x401d4290 + 0x0024e> in :0 --- End of inner exception stack trace --- at System.ServiceModel.Description.MetadataExchangeClient.GetMetadataInternal (System.ServiceModel.EndpointAddress address, MetadataExchangeClientMode mode) <0x401d4290 + 0x002f7> in :0 at System.ServiceModel.Description.MetadataExchangeClient.GetMetadata (System.Uri address, MetadataExchangeClientMode mode) <0x401d3df0 + 0x0005b> in :0 at Microsoft.Xrm.Sdk.Client.ServiceMetadataUtility.RetrieveServiceEndpointMetadata (System.Type contractType, System.Uri serviceUri, Boolean checkForSecondary) <0x401cea20 + 0x00297> in :0 at Error (native) at :1:55 at new CRMClient (/home/deploy/Projects/crm-rest/dynamicsintegration/node_modules/dynamicsintegration/CRM/CRMClient.js:34:26) at Object. (/home/deploy/Projects/crm-rest/dynamicsintegration/test.js:3:11) at Module._compile (module.js:434:26) at Object.Module._extensions..js (module.js:452:10) at Module.load (module.js:355:32) at Function.Module._load (module.js:310:12) at Function.Module.runMain (module.js:475:10) at startup (node.js:117:18)

ariskemper avatar Dec 18 '15 10:12 ariskemper

@ariskemper It looks like a name resolution failure based on your trace.

System.ServiceModel.EndpointNotFoundException: System error. ---> System.Net.WebException:     Error: NameResolutionFailure

Have you tried downloading the wsdl first, and check if there are references to other servers? Sometimes the wsdl has references to other data types (like .xsd files) which might be returned using server names.

Try adding those to your /etc/hosts file.

jordimontana82 avatar Dec 18 '15 10:12 jordimontana82

@ariskemper , this definitely looks like a network issue.

http://stackoverflow.com/questions/8999616/httpwebrequest-nameresolutionfailure-exception-in-net-with-mono-on-ubuntu

There are some tweaks in the above article that may help.

Anyway, would you be able to compile a .net console application to see if it connects well to your CRM server? I can send you the code if you want.

crisfervil avatar Dec 18 '15 11:12 crisfervil

@crisfervil we will also try module with Dynamics CRM 2016. You could send me the .net console application code. Thanks

ariskemper avatar Dec 18 '15 11:12 ariskemper

@ariskemper , is just a simple piece of code to test if it connects properly.

Add the CRM dlls, compile and run. If it connects successfully, the problem must be DynamicsIntegration.

References to be added, from CRM sdk:

Microsoft.Xrm.Client Microsoft.Xrm.Sdk Microsoft.Crm.Sdk.Proxy

using Microsoft.Crm.Sdk.Messages;
using Microsoft.Xrm.Client;
using Microsoft.Xrm.Client.Services;
using System;
using System.Net;

namespace DynamicsIntegrationTest
{
    class Program
    {
        static void Main(string[] args)
        {
            string connectionString = "Url=http://crm.contoso.org/MyOrgName";
            WebRequest.DefaultWebProxy = WebRequest.GetSystemWebProxy();
            WebRequest.DefaultWebProxy.Credentials = CredentialCache.DefaultNetworkCredentials;
            // Establish a connection to the organization web service using CrmConnection.
            var connection = CrmConnection.Parse(connectionString);
            var orgService = new OrganizationService(connection);

            // Test the connection
            var userId = ((WhoAmIResponse)orgService.Execute(new WhoAmIRequest())).UserId;
            Console.WriteLine("Connection successful!");
            Console.Read();
        }
    }
}

crisfervil avatar Dec 18 '15 12:12 crisfervil

@crisfervil: Tested with Dynamics CRM 2016. Running this code i get:

Unhandled Exception: System.InvalidOperationException: Metadata contains a reference that cannot be resolved : https://crmsrv.example.com/Organization/XRMServices/2011/Organization.svc?wsdl&sdkversion=7.1 ---> System.ServiceModel.FaultException: An error occurred when verifying security for the message. at (wrapper managed-to-native) System.Object:__icall_wrapper_mono_remoting_wrapper (intptr,intptr) at (wrapper remoting-invoke) System.ServiceModel.Description.IMetadataExchange:Get (System.ServiceModel.Channels.Message) at System.ServiceModel.Description.MetadataExchangeClient.GetMetadataInternal (System.ServiceModel.EndpointAddress address, MetadataExchangeClientMode mode) <0x417e5900 + 0x0026a> in :0 --- End of inner exception stack trace --- at System.ServiceModel.Description.MetadataExchangeClient.GetMetadataInternal (System.ServiceModel.EndpointAddress address, MetadataExchangeClientMode mode) <0x417e5900 + 0x0032b> in :0 at System.ServiceModel.Description.MetadataExchangeClient.GetMetadata (System.Uri address, MetadataExchangeClientMode mode) <0x417e5330 + 0x00067> in :0 at Microsoft.Xrm.Sdk.Client.ServiceMetadataUtility.RetrieveServiceEndpointMetadata (System.Type contractType, System.Uri serviceUri, Boolean checkForSecondary) <0x417e0600 + 0x002fb> in :0 [ERROR] FATAL UNHANDLED EXCEPTION: System.InvalidOperationException: Metadata contains a reference that cannot be resolved : https://crmsrv.example.com/Organization/XRMServices/2011/Organization.svc?wsdl&sdkversion=7.1 ---> System.ServiceModel.FaultException: An error occurred when verifying security for the message. at (wrapper managed-to-native) System.Object:__icall_wrapper_mono_remoting_wrapper (intptr,intptr) at (wrapper remoting-invoke) System.ServiceModel.Description.IMetadataExchange:Get (System.ServiceModel.Channels.Message) at System.ServiceModel.Description.MetadataExchangeClient.GetMetadataInternal (System.ServiceModel.EndpointAddress address, MetadataExchangeClientMode mode) <0x417e5900 + 0x0026a> in :0 --- End of inner exception stack trace --- at System.ServiceModel.Description.MetadataExchangeClient.GetMetadataInternal (System.ServiceModel.EndpointAddress address, MetadataExchangeClientMode mode) <0x417e5900 + 0x0032b> in :0 at System.ServiceModel.Description.MetadataExchangeClient.GetMetadata (System.Uri address, MetadataExchangeClientMode mode) <0x417e5330 + 0x00067> in :0 at Microsoft.Xrm.Sdk.Client.ServiceMetadataUtility.RetrieveServiceEndpointMetadata (System.Type contractType, System.Uri serviceUri, Boolean checkForSecondary) <0x417e0600 + 0x002fb> in :0

ariskemper avatar Dec 18 '15 15:12 ariskemper

@ariskemper The problem may be related either to the CRM deployment or the network configuration.

Could you try to access to another CRM server from the same machine? For example a CRM online. This will discard problems with the Server configuration.

Also you can try to run the same DynamicsIntegration script from another PC in the same network. Also a test in a Windows PC may discard issues with Mono or the Ubuntu configuration.

Thanks,

crisfervil avatar Dec 18 '15 17:12 crisfervil

I tried to connect and works on Windows machine which is in the same network and domain. In Ubuntu problem still exist even, if i used powerbroker (pbis) to join machine in domain.

ariskemper avatar Jan 10 '16 15:01 ariskemper

i am getting the same error, running code on https://tonicdev.com/npm/dynamicsnode but when i hit link i get in error for example. http://abc.example.com/Organization/XRMServices/2011/Organization.svc?wsdl&sdkversion=7.1, in my browser i get xml data properly.

pradeep-mishra avatar Aug 08 '16 15:08 pradeep-mishra

@pradeep-mishra , I got the same error while connecting to online CRM 2016.

Fix for my problem. The reason it is browsable from browser and not through .net client is browser already has windows login credentials. But .net client doesn't take them until specified explicitly.

Added below section in config file and worked.

<system.net>
    <defaultProxy useDefaultCredentials="true" >
    </defaultProxy>
</system.net>

avinashlanka avatar Sep 07 '16 15:09 avinashlanka

@avinashlanka Thanks for the info. Where did you add that config file?

@pradeep-mishra what OS are you connecting from?

crisfervil avatar Sep 07 '16 17:09 crisfervil

@crisfervil , I was trying to create Organization proxy for online instance through my companies network (code written in console application - same code as above). When I tried to browse the URL from my browser - wsdl renders. Got error "Metadata contains a reference that cannot be resolved" while creating proxy.

To solve, Added useDefaultCredentials="true" in console application config.

avinashlanka avatar Sep 08 '16 10:09 avinashlanka

@avinashlanka
@ariskemper I have the same error when I run it on mono. Do you guys have any idea to fix it?

hanpeic avatar Jun 20 '17 02:06 hanpeic

@hanpeic I'm afraid this project won't work in Mono, due to a couple of bugs not yet resolved and a few missing WPF libraries.

I have my hopes in .net Core to be able to run this in Ubuntu, but again, we still need to wait until the System.Xaml.dll is available in the platform.

Why System.Xaml.dll ? There's a dependency to this dll in one of the CRM SDK Assemblies (Microsoft.Xrm.Sdk.Workflow), and even though none of the DynamicsNode code references Workflows, this library is still required when a connection to the server is made.

What version of CRM are you trying to connect to? There's a Web Api endpoint available in CRM, that would be very simple to interact with using node. More info here: https://msdn.microsoft.com/en-us/library/mt593051.aspx

crisfervil avatar Jun 20 '17 10:06 crisfervil

@crisfervil Thanks for you message. I try to ask them do they have other api.

hanpeic avatar Jun 21 '17 00:06 hanpeic

Update Microsoft.Xrm.Sdk.dll

OR

Use this code above connection string

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

saddamk206 avatar Feb 05 '18 07:02 saddamk206