How to Upgrade Web API to Web API 2 - asp.net-web-api

I got some information for upgrading MVC 4 and Web API to MVC 5 and Web API 2
http://www.asp.net/mvc/tutorials/mvc-5/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and-web-api-2
I followed the steps from that hyperlink.
For upgrading from Web API to Web API 2, in global.asax, change:
WebApiConfig.Register(GlobalConfiguration.Configuration);
to
GlobalConfiguration.Configure(WebApiConfig.Register);
I am unable to find Configure() under GlobalConfiguration. Am I missing any reference here or am I supposed to include any definition or namespace?

if you have :
using System.Web.Http;
at the top of your file, then check if your project is actually referencing MVC 5 / Web API 2 assemblies

Related

Is IdentityService available in ASP.NET Core 2 Release?

I have ASP.NET Core created using MVC template with individual authentication.
In ASP.NET Core 1.1 ApplicationDbContext was used for identity.
Then in Core 2 Preview they added IdentityService instead, so I modified my project to use it.
But now after Core 2 Release I see they returned back to use ApplicationDbContext, how it was in Core 1.1.
So when I open project I get a lot of errors:
Should I install some Nuget? But I see only version 1.0 Preview for IdentityService:
Maybe I should return back and use ApplicationDbContext for identity instead?
UPDATE: Just found on GitHub: ASP.NET Core Identity as a service

Service Layer with WebApi

I am starting to work on a new project so working on laying on the architechture at this moment.
So basically we want to keep a service oriented architecture using MVC web api.
So I had the following structure in mind:
Project.Core (All Poco classes)
Proect.Data (All entity framerwork)
Project.Service (All Web API ??)
Project.Web
We would be working for the first time on webapi here. So wanted to know how do we intergrate webapi here.
Most of the articles we saw read had created a mvc web application and had selected webapi in that. But we
were looking to create separate service layer just for webapi. Is this the correct practice to do that or
I am missing something here.
We basically wanted not to have a tight coupling b.w MVC web and web api here. If we create web api as part
of mvc then how can we separately access our web api.
WOuld appreciate inputs.
I normally use the project template provided by Visual Studio. Choose Empty ASP.NET project template and then select Add folders and references for Web API. It will create the folder structure needed/recommended purely for a Web API project without any MVC reference. I generally create a separate project for Data Access and use that from the Web API project.

EF7: DBContext configuration on ASP.NET 5 Web-API

I'm currently developing an ASP.NET 5 Web-API application with VS2015 Ultimate Preview. Some things have changed about configuring EF7 on this new platform.
I've already checked the help in this page: https://github.com/aspnet/EntityFramework/wiki but it doesn't show all the step needed to successfully complete a connection with EF7 (it shows only a partial answer)
Can anyone bring a step-by-step tutorial on how would be the correct way to connect to a database (SQL Server) using EF7?. (not using old syntax like in MusicStore sample app but using more recent syntax)
The code should be the same as you linked in the sample app. You register the context in Startup.cs, within ConfigureServices method using the following code:
public void ConfigureServices(IServiceCollection services)
{
// Add EF services to the services container.
services
.AddEntityFramework(Configuration)
.AddSqlServer()
.AddDbContext<MyDbContext>(options =>
{
options.UseSqlServer(Configuration.Get("Data:DefaultConnection:ConnectionString"));
});
}
Then your MyDbContext will be available for dependency injection, and in your controllers you can do
public MyController(MyDbContext context)
{
...
}
That's it
The following tutorials helped me :
Introduction to Web API : Part 2 – Integrating with Entity Framework 5 Code First
Generic Repository Pattern with Entity Framework and Web API
Building an ASP.NET MVC4 Application with EF and WebAPI
Entity Framework Code First and ASP.NET Web API
Getting started with ASP.NET 5 MVC 6 Web API & Entity Framework 7
Stephen Walther has an updated Music Store tutorial. It starts here

WCF or Asp.Net MVC for API acess?

I wanted to get some thoughts about API access either through WCF or MVC. Either works, but I like the idea of using MVC to build custom routes. I know this is possible with WCF (maintaining the request routes), but aside form the security disadvantages of not using WCF (which are not deal breakers) what other thoughts does the community have regarding this.
I have a project where we have been discussion using MVC or WCF and we are comfortable with both, but we are swaying towards MVC.
You should use the new ASP.Net MVC Web API framework, new to MVC 4.0.
I think MVC makes a great web API. I did this not too long ago for an android app that uses a RESTful web API using MVC 3. Here's a good tutorial:
http://msdn.microsoft.com/en-us/magazine/dd943053.aspx
If you're feeling adventurous check out the Web API framework included in MVC 4. NOTE: I have not experimented with this yet but plan to in the near future. See here: http://www.asp.net/web-api

ASP.NET MVC 3 and WSE 2.0

I've an ASP.NET MVC 3 project and have been tasked with implementing a few UI controls. I need to call a few web services and bind the data to the UI controls. The problem is the web services host (we have no control over them) requires me to first implement a UsernameToken class (WSE 2.0) to authenticate the user and generate a security token. I understand WSE 2.0 is superceded by WCF in 2006. I don't want to switch back to VS 2005 to be able to use WSE 2.0. What are my options?
Thanks for any help!
Just add a Service Reference to your ASP.NET MVC application and point it to the web service WSDL. This will generate a strongly typed WCF client which is compatible with WSE. Here's an article which covers the different interoperability scenarios
I'm afraid the approach Darin Dimitrov didn't work. What I have ultimately done is installed WSE 2.0, then added dll reference to Microsoft.Web.Services2.dll found in the WSE installtion directory (c:\Program Files (x86)\Microsoft WSE\v2.0\Microsoft.Web.Services2.dll). I also modified the Reference.cs file of the service to inherit from Microsoft.Web.Services2.WebServicesClientProtocol. I was able to find the UsernameToken class and able to authenticate successfully.
I'm not an expert in this area so I'm not sure if this is the correct way of doing this, but it worked nonetheless.

Resources