“Metadata contains a Reference cannot be resolved” error for WCF service

By
Published 11-30-2020 02:48 PM 913 Views
Microsoft

While trying to make a WCF service to connect Dynamics 365, I came across to this error message:

 

Message Metadata contains a reference that cannot be resolved: ‘https://dynamics.com/test.svc?wsdl&sdkversion=9’. >> StackTrace at System.ServiceModel.Description.MetadataExchangeClient. MetadataRetriever.Retrieve(TimeoutHelper timeoutHelper)\r\n

 

Nedim_1-1606776487439.jpeg

 

We also saw the error below during testing:

 

InnerException System.Net.WebException: Unable to connect to the remote server —> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

 

Root Cause

 

Dynamics 365 started requiring TLS 1.2 after version 9.x (Reference). Connections that don’t use TLS 1.2 started failing after this update.

 

Solution

 

Force WCF service to use TLS 1.2 to solve this issue. One way of forcing it is to use the following line in the application:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

 

 

%3CLINGO-SUB%20id%3D%22lingo-sub-1942577%22%20slang%3D%22en-US%22%3E%E2%80%9CMetadata%20contains%20a%20Reference%20cannot%20be%20resolved%E2%80%9D%20error%20for%20WCF%20service%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1942577%22%20slang%3D%22en-US%22%3E%3CP%3EWhile%20trying%20to%20make%20a%20WCF%20service%20to%20connect%20Dynamics%20365%2C%20I%20came%20across%20to%20this%20error%20message%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3E%3CEM%3EMessage%20Metadata%20contains%20a%20reference%20that%20cannot%20be%20resolved%3A%20%E2%80%98%3CA%20href%3D%22https%3A%2F%2Fdynamics.com%2Ftest.svc%3Fwsdl%26amp%3Bsdkversion%3D9%E2%80%99%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Ehttps%3A%2F%2Fdynamics.com%2Ftest.svc%3Fwsdl%26amp%3Bsdkversion%3D9%E2%80%99%3C%2FA%3E.%20%26gt%3B%26gt%3B%20StackTrace%20at%20System.ServiceModel.Description.MetadataExchangeClient.%20MetadataRetriever.Retrieve(TimeoutHelper%20timeoutHelper)%5Cr%5Cn%20%3C%2FEM%3E%3C%2FP%3E%0A%3CDIV%20id%3D%22tinyMceEditorNedim_0%22%20class%3D%22mceNonEditable%20lia-copypaste-placeholder%22%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Nedim_1-1606776487439.jpeg%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F236737i45CBBBA9746241A2%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Nedim_1-1606776487439.jpeg%22%20alt%3D%22Nedim_1-1606776487439.jpeg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20also%20saw%20the%20error%20below%20during%20testing%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3E%3CEM%3EInnerException%20System.Net.WebException%3A%20Unable%20to%20connect%20to%20the%20remote%20server%20%E2%80%94%26gt%3B%20System.Net.Sockets.SocketException%3A%20A%20connection%20attempt%20failed%20because%20the%20connected%20party%20did%20not%20properly%20respond%20after%20a%20period%20of%20time%2C%20or%20established%20connection%20failed%20because%20connected%20host%20has%20failed%20to%20respond%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%3C%2FEM%3E%3C%2FP%3E%0A%3CH2%20style%3D%22font-style%3A%20inherit%3B%22%20id%3D%22toc-hId--1183674451%22%20id%3D%22toc-hId--1183674481%22%3ERoot%20Cause%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EDynamics%20365%20started%20requiring%20TLS%201.2%20after%20version%209.x%20(%3CA%20href%3D%22https%3A%2F%2Fsupport.microsoft.com%2Fen-us%2Fhelp%2F4051700%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EReference%3C%2FA%3E).%20Connections%20that%20don%E2%80%99t%20use%20TLS%201.2%20started%20failing%20after%20this%20update.%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1303838382%22%20id%3D%22toc-hId-1303838352%22%3E%26nbsp%3B%3C%2FH2%3E%0A%3CH2%20id%3D%22toc-hId--503616081%22%20id%3D%22toc-hId--503616111%22%3ESolution%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EForce%20WCF%20service%20to%20use%20TLS%201.2%20to%20solve%20this%20issue.%20One%20way%20of%20forcing%20it%20is%20to%20use%20the%20following%20line%20in%20the%20application%3A%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-csharp%22%3E%3CCODE%3EServicePointManager.SecurityProtocol%20%3D%20SecurityProtocolType.Tls12%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1942577%22%20slang%3D%22en-US%22%3E%3CP%3EWhile%20trying%20to%20make%20a%20WCF%20service%20to%20connect%20Dynamics%20365%2C%20%E2%80%9CMetadata%20contains%20a%20Reference%20cannot%20be%20resolved%E2%80%9D%20error%20may%20show%20up%3C%2FP%3E%3C%2FLINGO-TEASER%3E
Co-Authors
Version history
Last update:
‎Apr 13 2021 11:56 AM
Updated by: