diff --git a/src/Dynamicweb.DataIntegration.Providers.ODataProvider.csproj b/src/Dynamicweb.DataIntegration.Providers.ODataProvider.csproj index 5ff6466..a4a3a82 100644 --- a/src/Dynamicweb.DataIntegration.Providers.ODataProvider.csproj +++ b/src/Dynamicweb.DataIntegration.Providers.ODataProvider.csproj @@ -1,6 +1,6 @@  - 10.6.7 + 10.6.8 1.0.0.0 OData Provider The Odata Provider lets you fetch and map data from or to any OData endpoint. diff --git a/src/ODataProvider.cs b/src/ODataProvider.cs index de4ad82..141abcd 100644 --- a/src/ODataProvider.cs +++ b/src/ODataProvider.cs @@ -15,6 +15,7 @@ using System.Linq; using System.Net; using System.Net.Http; +using System.Text.Json; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Xml; @@ -129,6 +130,19 @@ public string DestinationEndpointId #endregion private string GetMetadataURL() + { + if (GetEndpointResponse(ODataSourceReader.GetEndpointUrlWithTop(_endpoint.Url), out string endpointResponse, out Exception exception) == HttpStatusCode.OK && exception is null) + return GetMetadataURLFallBack(); + + using var responseJson = JsonDocument.Parse(endpointResponse); + + if (responseJson.RootElement.ValueKind != JsonValueKind.Object) + return GetMetadataURLFallBack(); + + return responseJson.RootElement.EnumerateObject().FirstOrDefault(obj => obj.Name.Equals("@odata.context", StringComparison.OrdinalIgnoreCase)).Value.GetString() ?? GetMetadataURLFallBack(); + } + + private string GetMetadataURLFallBack() { if (_endpoint.Url.Contains("companies(", StringComparison.OrdinalIgnoreCase)) { @@ -164,7 +178,7 @@ internal void SetCredentials() var endpointAuthentication = _endpoint.Authentication; if (endpointAuthentication != null) { - var metadataUri = new Uri(GetMetadataURL()); + var metadataUri = new Uri(_endpoint.Url); var credentialCache = new CredentialCache { { new Uri(metadataUri.GetLeftPart(UriPartial.Authority)), endpointAuthentication.Type.ToString(), endpointAuthentication.GetNetworkCredential() }