Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid Context URL #679

Open
ChrisGrove opened this issue Oct 21, 2019 · 1 comment
Open

Invalid Context URL #679

ChrisGrove opened this issue Oct 21, 2019 · 1 comment

Comments

@ChrisGrove
Copy link

Hi,
when connecting to and querying the api for our MIS system I get the following error:

The context URL 'https://xxx.xxx-xxx.co.uk/api/$metadata#schools/Wcbs.Domain.Models.Projections.SchoolDetails' (actual url removed for security).

The full stack trace is:

at Microsoft.OData.JsonLight.ODataJsonLightContextUriParser.ParseContextUriFragment(String fragment, Func3 clientCustomTypeResolver, Boolean throwIfMetadataConflict, Boolean& isUndeclared) at Microsoft.OData.JsonLight.ODataJsonLightContextUriParser.ParseContextUri(ODataPayloadKind expectedPayloadKind, Func3 clientCustomTypeResolver, Boolean throwIfMetadataConflict)
at Microsoft.OData.JsonLight.ODataJsonLightContextUriParser.Parse(IEdmModel model, String contextUriFromPayload, ODataPayloadKind payloadKind, Func3 clientCustomTypeResolver, Boolean needParseFragment, Boolean throwIfMetadataConflict) at Microsoft.OData.JsonLight.ODataJsonLightDeserializer.ReadPayloadStart(ODataPayloadKind payloadKind, PropertyAndAnnotationCollector propertyAndAnnotationCollector, Boolean isReadingNestedPayload, Boolean allowEmptyPayload) at Microsoft.OData.JsonLight.ODataJsonLightReader.ReadAtStartImplementation() at Microsoft.OData.ODataReaderCore.ReadImplementation() at Microsoft.OData.ODataReaderCore.ReadSynchronously() at Microsoft.OData.ODataReaderCore.InterceptException[T](Func1 action)
at Microsoft.OData.ODataReaderCore.Read()
at Simple.OData.Client.V4.Adapter.ResponseReader.ReadResponse(ODataReader odataReader, IODataResponseMessageAsync responseMessage)
at Simple.OData.Client.V4.Adapter.ResponseReader.d__3.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() at Simple.OData.Client.ODataClient.<ExecuteRequestWithResultAsync>d__1471.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() at Simple.OData.Client.ODataClient.<FindAnnotatedEntriesAsync>d__88.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult()
at Simple.OData.Client.ODataClient.d__89.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() at Simple.OData.Client.FluentClientBase2.d__91.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at WcbsApiTest.Program.d__3.MoveNext() in D:\Code\ScratchPad\OAuth2\WcbsApiTest\WcbsApiTest\Program.cs:line 117

The calling code is:

 public static async Task GetSchoolsAsync(string authToken)
        {
            var httpClient = new HttpClient
            {
                BaseAddress = new Uri("https://xxx.xxx-xxx.co.uk/")
            };

            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authToken);

            var client = new ODataClient(new ODataClientSettings(httpClient, new Uri("api", UriKind.Relative))
            {
                IgnoreResourceNotFoundException = true,
                OnTrace = (x, y) => Console.WriteLine(string.Format(x, y))

            });

            try
            {
                //var schools = await client.For("Schools").FindEntriesAsync();
                var schools = await client.For<School>().FindEntriesAsync();

                foreach (var school in schools)
                {
                    Console.WriteLine(school.Description);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw;
            }

        }

I have tried both the typed and untyped syntax and the error is the same.

The above code works with OData reference services.

Sample response from the service:

{
  "@odata.context": "https://xxx.xxx-xxx.co.uk/api/$metadata#schools/Wcbs.Domain.Models.Projections.SchoolDetails",
  "value": [
    {
      "@odata.type": "#Wcbs.Domain.Models.Projections.SchoolDetails",
      "Id": 1,
      "Code": "XX",
      "Description": "xxx xxx"
    }
  ]
}
@rahul7720
Copy link

Any updates on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants