Wrong url set by Breeze for getting the Metadata from ASP.NET Web API OData Service - asp.net-web-api

I am working on a SPA using Durandal, Breeze and Knockout. The back-end service is provided by ASP.NET Web API OData.
I have configured the Breeze to work with OData like this:
breeze.config.initializeAdapterInstances({ dataService: "OData" });
and have set the remote service name in Breeze to 'odata'.
The thing is that the uri that Breeze calls to get the metadata is odata/$metadata whereas the uri that seems to work properly (have tested in Fiddler) is odata?$metadata.
Am I missing something?

For Web API OData you should use:
breeze.config.initializeAdapterInstances({ dataService: "webApiOData" });
just odata is used for wcf odata.

Related

How to call Rest request from jsp

I have to create 2 projects. Web Service and one is Web project.
I created the web service using Rest in spring boot and web project using dynamic web project using Jsp and servlets.
Now I have to consume the web service in web project. How can I do ?
You can do AJAX call from your JSP side to your REST server side using Javascript. You can also use library like JQuery or axios (there MDN versions since you are using JSP) to send REST API calls to your same or any other server. You can follow https://stackoverflow.com/a/44859872/8684299 this answer.

In ASP.NET Core 3.0 API, how do I implement JWT Bearer Tokens

I am starting on a new web API and I want to use ASP.NET Core 3.0. I also want to authorize callers to my API using JWTs and Azure AD as the Identity Provider.
I have set up many ASP.NET Core 2.x web APIs using JWTs and Azure AD that have worked just fine, however, when I try the same methods using ASP.NET Core 3.0 I get a 401 every time I try to access the API.
In my ASP.NET Core 2.2 web API, in Startup.cs I have the following in the ConfigureServices method;
// Add Azure AD OAUTH2.0 Authentication Services
services.AddAuthentication(sharedOptions =>
{
sharedOptions.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddAzureAdBearer(options => Configuration.Bind("AzureAd", options));
And I have an AzureAd section in my appsettings.json file that have values for...
"AzureAd": {
"Instance": "https://login.microsoftonline.com/",
"Domain": "mydomain.com",
"TenantId": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX", //<-- Directory ID for mydomain.com
"ClientId": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" //<-- Application ID of web API as a registered application in mydomain.com domain
},
Then in Startup.cs --> Configure method, I have ...
app.UseAuthentication();
app.UseMvc();
And finally, I decorate my API controller with...
[Authorize]
And this all works just fine for ASP.NET Core 2.2.
However, after creating a new project for an ASP.NET Core 3.0 Web API, and trying to implement the same techniques, I always get an HTTP 401 status code.
I realize the ASP.NET Core 3.0 was just released and I have to assume that the issue is related to changes in the way Core 3.0 operates, but I am having difficulty finding a solution.
Update 10/2/19
I test my APIs using Postman. In Postman, I make a POST to Azure AD with the correct values needed to obtain the access token from Azure AD. I copy that valid token to the Authorization header in a GET request to my API.
If I set my API to ASP.NET Core 2.2 and run it, then test the API using Postman as described above, my API authorizes the request and returns the correct data in the GET request's response.
If I change the API to ASP.NET Core 3.0 and try it again, I always get an HTTP 401.
The issue has to be a difference between how ASP.NET Core 3.0 handles JWT authorization and how ASP.NET Core 2.2 does it.

Use BreezeJS and JayData Without OData

Can we use BreezeJS or JayData, with all of their features without OData (i.e using only ASP.NET Web API but without OData)?
Breeze already supports this as it's default. Breeze, by default, uses an OData format over the wire for query purposes, but this does NOT require that the server be implemented as an OData service. The standard Breeze WebApi server controller can understand this format without you having to implement an OData service. ( the same is true of our Mongo and Ruby server examples).
In fact, most of the Breeze examples show Breeze communicating directly with ASP.NET Web Api without using any of the WebApi OData implementation.

Are there limitations converting a WCF OData Service to a Web API OData Service?

We have some legacy OData service code in our application which is written using a WCF Data Service.
Everything else in our system now uses Web API as the data interface so I am wanting to port our WCF OData Service to a Web API service with the OData annotations.
My question is, we currently use the OData service for standard CRUD statements and also a lot of Service Operations. Are there any limitations with Web API OData that would limit it compared to WCF Data Services (i.e relationship chains, service operation calls, etc.)? I'm wanting to get away with updating the service so the client side of things doesn't have to change at all.
I've started working on a similar port from WCF to WebAPI for OData with the recent release of Web API 2 and its support for $select and $expand - until then I could not really replace the data service. Service operations can be added as actions

What replaced HttpOperationHandler in WCF Web API to ASP.NET Web API

In upgrading an old project that was built using WCF Web API to now use ASP.NET Web API, I have run into a few classes that implement HttpOperationHandler<HttpRequestMessage, T>. I'm unable to find an equivalent class in the new assemblies. Does something similar exist or will I need a different approach?
The concept of Operation handlers has been replaced with Filters and model binders.
Here are some links that you might find useful:
How to Migrate from WCF Web API to ASP.NET Web API
Mike's blog on How WebAPI does Parameter Binding
Getting started tutorials on ASP.NET WebAPI page.
Hope this helps.

Resources