1
votes

I have windows service which access Microsoft Dynamics CRM 2011.

I have a problem windows service giving exception when it trying to connect to CRM 2011.

It works fine when we run service directly from server.

I have an administrator privileges on CRM Organization what I am trying to connect.

This is the code where connecting to CRM:

  private OrganizationServiceProxy BuildCRMServiceProxy()
     {
         var credentials = new ClientCredentials();            
         var orgConfigInfo = ServiceConfigurationFactory.CreateConfiguration<IOrganizationService>(OrganizationUri);
         return new OrganizationServiceProxy(orgConfigInfo, credentials);
     }

The exception is as below:

ERROR 2013-08-21 09:27:47,958 [8] System.InvalidOperationException: Metadata contains a reference that cannot be resolved: 'http://***/XRMServices/2011/OrganizationData.svc?wsdl'. ---> System.Net.WebException: The remote server returned an error: (401) Unauthorized. at System.Net.HttpWebRequest.GetResponse() at System.ServiceModel.Description.MetadataExchangeClient.MetadataLocationRetriever.DownloadMetadata(TimeoutHelper timeoutHelper) at System.ServiceModel.Description.MetadataExchangeClient.MetadataRetriever.Retrieve(TimeoutHelper timeoutHelper) --- End of inner exception 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 Microsoft.Xrm.Sdk.Client.ServiceMetadataUtility.RetrieveServiceEndpointMetadata(Type contractType, Uri serviceUri, Boolean checkForSecondary) at Microsoft.Xrm.Sdk.Client.ServiceConfiguration1..ctor(Uri serviceUri, Boolean checkForSecondary) at Microsoft.Xrm.Sdk.Client.ServiceConfiguration1..ctor(Uri serviceUri) at Microsoft.Xrm.Sdk.Client.OrganizationServiceConfiguration.AdjustServiceEndpoint(Uri serviceUri) at Microsoft.Xrm.Sdk.Client.OrganizationServiceConfiguration..ctor(Uri serviceUri) at Microsoft.Xrm.Sdk.Client.ServiceConfigurationFactory.CreateConfiguration[TService](Uri serviceUri) at *.DynamicsUpdater.ServiceAgent.DynamicsAgent.BuildCRMServiceProxy() at **.DynamicsUpdater.ServiceAgent.DynamicsAgent.InsertEntity(String entityName, Boolean isRelationship, Dictionary2 attributes, Guid& generatedId) at ******.DynamicsUpdater.BusinessLogic.CRMProcessorFactory.<>c__DisplayClass3d1.b__3c(Update update, ICRMRepository CRM, IUpdatesRepository updatesRepo) at **.DynamicsUpdater.BusinessLogic.Controllers.ApprovedUpdateController.<>c_DisplayClass3.b_1(Boolean wasProcessedYet, Func4 processor) at System.Linq.Enumerable.Aggregate[TSource,TAccumulate](IEnumerable1 source, TAccumulate seed, Func3 func) at ******.DynamicsUpdater.BusinessLogic.Controllers.ApprovedUpdateController.Process(Update update) at ******.DynamicsUpdater.BusinessLogic.Controllers.UpdateControllerBase.Execute(Func1 retrieveUpdateForProcessingCallback) at **.DynamicsUpdater.Updater.<>c_DisplayClassb.b_a()


Its work fine when we run it from windows server 2008 but not when I run from my desktop windows 7 64 bit.

2

2 Answers

2
votes

Looks like you're not providing valid credentials to the server. Is your desktop in the same network as the server? If so, try NetworkCredential:

credentials.Windows.ClientCredential = new System.Net.NetworkCredential("username", "password", "domain");
0
votes

i was having same problem (ERROR : Metadata contains a reference that cannot be resolved )

but this error comes when i create new project called "New Visual Studio Solution Template for Dynamic CRM 2013" in Dynamic CRM node of C# in visual studio 2010.

it ask for domain name , and port number first and if u don't provide a valid domain name , it gives such error Domain name u will get from discovery service wsdl and no need to provide port , it will automatically fetch the available one . and than insert your credential and now you can create a project , which can be deployed on cloud .