MVC and Web API in a single project?

Hi,
I currently have a MVC 5 application using EF6 and we need to add Web API on top of it.  I can simply scaffold new Web API controller using different controller name within the same project but I don't feel it is the best solution.  For example.
if I have a MCV5 controller called "phonebook", I would have to call the WebAPI controller phonebooksAPI (or something else) .. Then, when I need to call the WebApi, it would be something like /api/phonebooksAPI.
So, is it possible to have my MCV controller at /phonebook and the WebAPI controller at: /api/phonebook ?  Should I create the 2 different projects, which mean I would have to redo my EF model binding (they should be the same in both MVC and WebAPI).
What are the best practices on that.  I've read a bit on the web but many people are having different way of doing this, and different opinion.  So what do you think Microsoft Expert ?! ;)
Best regards.

Hello Elezium38,
Welcome to MSDN forum.
Your issue is out of support range of VS General Question forum which mainly discusses
the usage of Visual Studio IDE such as WPF & SL designer, Visual Studio Guidance Automation Toolkit, Developer Documentation and Help System
and Visual Studio Editor.
Because your issue is related to ASP.NET MVC Application, I suggest that you can consult your issue on ASP.NET forum:
http://forums.asp.net/
 for better solution and support.
Best regards,
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey.

Similar Messages

  • RRI drilldown on structures using javascript and Web API

    Hi SDN community,
    We have devised a method to RRI on structure elements using javascript and Web API statements:
    var url = SAP_BW_URL_Get();
    zREP_UNIT_VAR1 = "ZN_MRU01";
    zREP_UNIT_VAR2 = "ZP_FPER";
    var zeroFISCYEARKey = getVar("ZPFYEAR");
    var zREP_UNITHierNodeKey = getVar("ZN_MRU01");
    var zREP_UNITHierNodeKey = trimString(zREP_UNITHierNodeKey);
    var zeroFISCPERVarKey = getVar("ZP_FPER");
    var zeroFISCPERKey = convertZeroFISCPERVarKeyToKey (zeroFISCPERVarKey);
    var zeroCURRENCYKey = getVar("ZPM_CURR");
    zREP_UNIT_TEMPLATE = "ZWT_CPERF_M50_UC_CHART";
    url = SAP_BW_URL_Get() + "&CMD=LDOC&TEMPLATE_ID=" + zREP_UNIT_TEMPLATE +"&VAR_NAME_1=" + zREP_UNIT_VAR1 + "&VAR_VALUE_EXT_1="  + zREP_UNITHierNodeKey  + "&VAR_NODE_IOBJNM_1=" + "0HIER_NODE" + "&VAR_NAME_2=" + zREP_UNIT_VAR2 + "&VAR_VALUE_EXT_2=" + zeroFISCPERKey + "&VAR_VALUE_EXT_3=" + zeroCURRENCYKey + "&CMD_1=DATA_PROVIDER%3DFY" + "%26FILTER_IOBJNM_1%3D"+ filter + "%26FILTER_VALUE_1%3D"  + parameter1 + "&CMD_2=DATA_PROVIDER%3DCMYTD" + "%26FILTER_IOBJNM_2%3D"+ filter + "%26FILTER_VALUE_2%3D"  + parameter1;
    SAPBWOpenWindow(url,"IO_Process_KPI_Report","width=screen.width, height=screen.height,menubar=yes, toolbar=no, scrollbars=yes, resizable=yes");
    Necessary conditions:
    The same Global Structure is in the Sender Query and the Target Query
    Question:
    Is there any other way to RRI on structure elements within a sender query to a target query using:
    BADI's, ABAP or any other method.
    Thank you.
    Simon

    Hi SDN Community,
    At the time of asking this question there were not many examples of BADI for RRI's.  I now see a number of examples we can use.
    Thank you.
    Simon

  • Export data to excel with EPPlus and Web Api - HELP!

    I am trying to do a simple excel file export with EPPlus and Web Api. In the html client I have a button that calls the web api and opens a new window. No error is thrown, but the result is always "file could not be downloaded".  I get the
    save file dialog but the file name is Order/ instead of the expected Orders.xls or Orders.xlsx.  Can anyone help? I'm surprised this is so difficult.
    using System.Linq;
    using System.Net.Http;
    using System.Web.Http;
    using OfficeOpenXml;
    using System.Collections.Generic;
    using System.IO;
    using System.Net.Http.Headers;
    using System.Net;
    using System.ComponentModel.DataAnnotations;
    namespace LightSwitchApplication
    public class OrdersController : ApiController
    // GET: api/Orders
    [HttpGet]
    public HttpResponseMessage Get()
    HttpResponseMessage response;
    response = Request.CreateResponse(HttpStatusCode.OK);
    MediaTypeHeaderValue mediaType = new MediaTypeHeaderValue("application/octet-stream");
    response.Content = new StreamContent(GetExcelSheet());
    response.Content.Headers.ContentType = mediaType;
    response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
    response.Content.Headers.ContentDisposition.FileName = "Orders.xls";
    return response;
    public List<Order> GetOrders()
    List<Order> colOrders = new List<Order>();
    using (ServerApplicationContext ctx = ServerApplicationContext.Current ??
    ServerApplicationContext.CreateContext())
    colOrders = ctx.DataWorkspace.Data.Orders.GetQuery().Execute().ToList();
    return colOrders;
    public MemoryStream GetExcelSheet()
    using (var package = new ExcelPackage())
    var worksheet = package.Workbook.Worksheets.Add("Orders");
    worksheet.Cells["A1"].LoadFromCollection(GetOrders(), false);
    package.Save();
    var stream = new MemoryStream(package.GetAsByteArray());
    return stream;
    This has been driving me crazy for two days!

    Making some progress.  I got the spreadsheet into a byte[] and used code from Paul Van
    Bladel's blog to make the HttpResponseMessage.  If I comment out the LightSwitch data access code, this works to export a spreadsheet from a static list to the browser from Web Api.
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Net;
    using System.Net.Http;
    using System.Net.Http.Headers;
    using System.Web.Http;
    using Microsoft.LightSwitch;
    using Microsoft.LightSwitch.Details;
    using OfficeOpenXml;
    using System.ComponentModel.DataAnnotations;
    namespace LightSwitchApplication
    public class Order
    [Key]
    public int Id { get; set; }
    public string OrderNumber { get; set; }
    public class OrdersController : ApiController
    // GET: api/Orders
    [HttpGet]
    public HttpResponseMessage Download()
    MediaTypeHeaderValue mediaType =
    MediaTypeHeaderValue.Parse("application/octet-stream");
    byte[] excelFile = ExcelSheet();
    string fileName = "Orders.xlsx";
    MemoryStream memoryStream = new MemoryStream(excelFile);
    HttpResponseMessage response =
    response = Request.CreateResponse(HttpStatusCode.OK);
    response.Content = new StreamContent(memoryStream);
    response.Content.Headers.ContentType = mediaType;
    response.Content.Headers.ContentDisposition =
    new ContentDispositionHeaderValue("fileName") { FileName = fileName };
    return response;
    public List<Order> Orders()
    List<Order> orders = new List<Order>();
    orders.Add(new Order { Id = 1, OrderNumber = "123456789" });
    orders.Add(new Order { Id = 2, OrderNumber = "987654321" });
    return orders;
    // this doesn't work
    //public List<Order> Orders()
    // List<Order> colOrders = new List<Order>();
    // using (ServerApplicationContext ctx = ServerApplicationContext.Current ??
    // ServerApplicationContext.CreateContext())
    // colOrders = ctx.DataWorkspace.Data.Orders.GetQuery().Execute().ToList();
    // return colOrders;
    public byte[] ExcelSheet()
    using (var package = new ExcelPackage())
    var worksheet = package.Workbook.Worksheets.Add("Orders");
    worksheet.Cells["A1"].LoadFromCollection(Orders(), false);
    byte[] bytes = package.GetAsByteArray();
    return bytes;
    The problem is that the LightSwitch query (commented out in the code above) is trying to load navigation properties for the orders.  Error: "It is not valid to access this object on the current thread."  How do I solve this? 

  • Using Web API and MVC to connect to CRM and ADFS

    Hi,
    I'm struggling trying to find best point start for a migration project.
    I have a web forms application that connects to CRM 2011 (Azure VM, Windows Server 2008 R2) using ADFS 2.1 (Azure VM, Windows Server 2012) for CRUD operations.
    An external developer has build the front end in AngularJS, so we have decided to migrate the project to MVC framework for the integration simplicity over web forms.
    Can you confirm if this is right?
    1. Should I use Web API as I'll be querying CRM?
    2. Should I have an MVC project as I need to authenticate against ADFS 2.1?
    3. If one answer of the above questions is NO, can I develop just an MVC or Web API project to achieve what I want?

    This forum supports setup of the .NET Framework itself.
    For best help with your MVC questions, I suggest you post here:
    http://forums.asp.net/1146.aspx/1?MVC

  • MVC Web API json response truncated?

    I have an MVC 4 Web API in C# hosted in IIS 7
    Basically this service has a queue that has items enqueued every minute. I expose a GET method that allows for all the items in the queue to be returned in a json array.
    the queue is really this: Queue<List<CustomObject>> mQueue; then every minute a new list is enqueued.
    The max size of the queue is 50 (1 hour of data)
    the maximum count of a list in said queue is ~500 and minimum count is ~100. When I debug the api locally It will return all the elemnets in the queue no problem. only takes a couple seconds. The size of the json response (saved to disk) is ~10Mb.
    So I decided to host this service on a VM. I let it run for a while so the queue gets populated. then I make my request:
    http://somepoint:4328/AzureQueueService?view=Full
    I only get 1.30 - 1.32 mb of data back. Which equates to about 4 minutes worth of data! So the question becomes is there some setting in IIS that forces the response sent to be less than 2Mb? Maybe there is a similar setting in my webconfig? Or maybe IIS
    has created more than one instance of my service? Either way, I'm missing something here.

    What OS (including SP number) your service is running on? (both local and VM)
    Do you receive the same amount of data as specified in Content-Length header? Is your response a valid JSON (just having less data than expected), or it is really truncated?
    Where is your queue hosted? Is it just a static object inside IIS process, or somewhere out-of-process?
    How is it filled? By another method passing incoming data? Do you use thread synchronization when accessing the queue?
    IIS may have multiple worker processes per application, and each will have its own static queue (of course, if it is hosted in-process). Also IIS might recycle worker processes, so in-process data could be lost.

  • Why is there no WSDL type support for Web Api?

    So I am just getting started with .Net WebApi and one thing that I am noticing straight away is that there is no Contract defining how the Api looks and should be consumed (Request/Responses from each Action), this is usually in the form of a WSDL for WCF/Soap.
    It seems to me like this is something that would be very valuable and make life a lot easier for consumers of your Api.
    Is there a reason there isn't one? Is there a programming paradime or principle that I am unaware of? Is there a way I could create one?

    SOAP, REST AND PEOPLE'S CREATIVITY
    SOAP needs a description document like WSDL because each resource can be consumed with different messages, there are no definition on the protocol about constraints to the possible names/messages that you can manipulate a resource.
    For example, in SOAP your web service that allow clients manipulate an user can expose the operation that create an user in many different messages, like:
    addUser
    createUser
    insertUser
    Of course, these are just few sample messages, because I've see a lot of funny web services method names. There are really creative people out there.
    In other hand, if you are exposing your underlying system using web api that really respect the REST principles, the client just need to know that you have a resource named Users, because there is 99% of chance that you can create an user in this way
    POST /Users
    And this occurs for each operation you want to expose using SOAP or a web api REST.
    Despite being SOAP a protocol, which restricts what you can or can not do, and be REST a style architecture, which leaves many open points of how to do things. There are efforts to define conventions of how to expose and consume REST web apis.
    DESCRIBING A WEB API REST
    In the field of how to describe a web api REST I can cite
    Swagger. It is not a attempt to create a WSDL like to web api REST, but it is a good attempt to create an open standard for describing web apis REST.
    Swagger is a specification and complete framework implementation for describing, producing, consuming, and visualizing RESTful web services.
    I use Swagger a lot and really love it, mainly because
    Swagger UI that allow you generate a nice live console and documentation for your web api.
    There are many implementations of Swagger for most of languages: C#, Java, Python, Ruby, etc.
    If you are using ASP .NET Web API, there a some projects to auto generate the Swagger specification, like
    Swagger.NET
    GENERATING CLIENTS TO A WEB API REST
    Because the constraints of REST, like the limited set of verbs (GET, POST, PUT, DELETE, etc) is not so difficuty to generate a client library to a web api REST.
    Projects like
    WebApiProxy can easily generate clients do C# and Javascript.
    CONVENTIONS FOR WEB API REST
    To keep our lifes as developers easier is good define some conventions of how our web api REST will behave, the best effort I know in this field is the very good
    Apigee - Web Api Design ebook. The e-book is not an attempt to create a bible or a mantra about how to design your api, but rather a collection of conventions observed in large web REST apis, like Twitter, Facebook, Linkedin, Google, etc.

  • Beginner's questions about WCF and web services

    For the purpose of this forum let me just say that I got my certs back in Dot Net 2.0.  I know how to write simple web services.  Now someone has dumped a huge package of code on my desk that (I think) contains a WCF project (without documentation
    of course).  Contains references to System.ServiceModel.
    So my questions...
    1.  What (if anything) is the difference between WCF and Web API?
    2.  If there is a difference,  how do you decide which one to use?
     3.  Assuming that this project on my desk is a WCF project, where can I find some hints on how to run it in VS2013 Community? 

    WEB API is restricted to ASP.NET and HTTP. 
    http://captechconsulting.com/blog/john-nein/aspnet-web-api-vs-windows-communication-foundation-wcf
    WCF uses more communication protocols than just HTTP, there are more ways to host a WCF service other than IIS, like a selfhosting exe type WCF server,   and WCF is a SOA solution.
    WCF is a more robust solution in a whole lot of ways is the bottom line.
    http://en.wikipedia.org/wiki/Service-oriented_architecture
    http://www.codeproject.com/Articles/515253/Service-Oriented-Architecture-and-WCF

  • How to upload to Azure Media Services when using HTML5 with Web API

    I keep finding examples demonstrating how to upload video to Azure Media Services through a console application.  I am developing an application using HTML5 with angularjs and web api, but am having trouble finding an example for uploading when you
    are getting the file from a form on a web browser.  The main issue I find is that I see a way to upload from a file path and no way to upload from a stream.  I would like to upload the file to blob storage and then associate the file in blob storage
    with the IAssetFile object, which is then associated with IAsset.  It this possible and if so can you point me in the direction of some tutorials that demonstrate this?  Also, I am allowing site members to upload videos and images.  For this
    images scenario, I saw doc. demonstrating how to start a job that will save the image into a different size, what if I need four different sizes for each image uploaded?

    Hi,
    the following example shows how to upload a stream into a blob and associate the blob with an asset: https://code.msdn.microsoft.com/How-to-upload-a-stream-to-d2750102.
    thanks,
    Julia
    This posting is provided "AS IS" with no warranties, and confers no rights.

  • WCF Rest Service Vs Web API

    1. What is difference between WCF REST SERVICE(and not WCF) and WebAPI?
    2. When we should one over another?
    Deepak Talele Ph: 91-9158413830 Email: [email protected], [email protected]

    Hi,
    Use WCF to create reliable, secure web services that accessible over a variety of transports. Use ASP.NET Web API to create HTTP-based services that are accessible from a wide variety of clients. Use ASP.NET Web API if you are creating and designing new
    REST-style services. Although WCF provides some support for writing REST-style services, the support for REST in ASP.NET Web API is more complete and all future REST feature improvements will be made in ASP.NET Web API.
    For the difference between WCF REST Service and web api, you could refer to the following links for more information:
    https://msdn.microsoft.com/en-us/library/jj823172(v=vs.110).aspx
    http://www.dotnet-tricks.com/Tutorial/webapi/JI2X050413-Difference-between-WCF-and-Web-API-and-WCF-REST-and-Web-Service.html
    Regards

  • MVC Web API in SharePoint site

    We're planning on moving most of our web presence on our SharePoint 2013 server in cloud. Our current setup uses a MVC Web API for data retrieval from DB. We do not want to host the API under a separate domain and thus need to move the API under SharePoint
    domain as well. There is no relaxation in this requirement.
    Is there a way to publish my API to SharePoint? Or is there a SharePoint specific API project template in Visual Studio? If not what are my options?

    Hi,
    According to your description, you might want to host the Web API in your SharePoint Online environment.
    If it is SharePoint Online, as we can’t access the backend server, your requirement might not be achievable at this moment.
    Your requirement is retrieving data from a database, as a workaround, you can use “the Business Connectivity Services (BCS) hybrid scenario to access on-premises data
    through SharePoint Online”:
    http://technet.microsoft.com/en-us/library/dn197239(v=office.15).aspx
    With the retrieved data from the database, you can create an External list, then access the data of this External list using Client Object Model.
    Or we can use an Azure SQL Server to sync with your database, then implement a Provider Hosted app to deal with the data from Azure SQL Server. The demo below would
    provide more details about this solution:
    http://blogs.msdn.com/b/alimaz/archive/2014/07/31/connect-sharepoint-online-to-an-on-premises-sql-server-from-an-azure-provider-hosted-app-using-hybrid-connections.aspx
    Best regards
    Patrick Liang
    TechNet Community Support

  • WCF and WP8.1: Can I only use WCF REST services? Then better WCF or Web API?

    I am trying to create a simple application to test WCF with WP8.1. I have created my service. Later I create my WP8.1 silver light application and I try to add a reference to my service Project. The problem is that I get an error that says that I have only
    add reference to projects that are Windows pone 8.
    I have read some solutions, but all of them are creating a WCF REST service, so my doubt if the WP8.1 applications only can connect to WCF REST services.
    In this case, if this is true, it not would be better to use Web API instead of WCF?
    Thanks so much.

    You can use any type of rest service with windows phone 8.1 because rest services can be called via the httpclient class.  You dont need a service reference.  Personally I prefer the web api but there is no reason you can not use a wcf rest service.

  • Using KM and Collaboration API in portal component and web dynpro

    Hi,
    I have to develop portal components and Web Dynpros (JAVA) which have to use the following functions:
    - copy, delete KM documents
    - sending E-Mails 
    Can anyone give me some actual documentation links for the KM and Collaboration APIs ?
    Which references do I need in portalapp.xml for KM/collaboration and which jar-Files do I have to add to the project?
    We are using NetWeaver 7.01 SP18.

    Hi  Yogalakshmi,
    thank you for the link and the information. Now I managed to work with the KM documents.
    One more Question: to get the resource Context, I use this code:
    portalUser = WPUMFactory.getServiceUserFactory().getServiceUser("cmadmin_service");
    IResourceContext resourceContext = new ResourceContext(portalUser);
    The method getServiceUser is deprecated, also the com.sapportals.portal.security.usermanagement.IUser is deprecated. Is there an other possibility to get the ResourceContext. (perhaps with com.sap.security.api.IUser) ?

  • Web API OData authentication and batch requests

    Hello,
    We have and OWIN middleware integrated into our web application pipeline which serves the purposes of authentication of OData requests by JWT token. On successful authentication we set the Thread and HttpContext principal to custom Principal object of ours.
    The problem arises when performing OData batch requests. The sub-requests of batch are executed in separate threads and with no HttpContext associated with it so we loose the authenticate principal in those requests. I guess this is due to the way OData batch
    requests are executed but our server logic strongly depends on custom Principal. The way we currently work around this is by using a custom ActionFilterAttribute that we apply to ODataControllers:
    public class LoginAttribute : ActionFilterAttribute
    public override void OnActionExecuting(HttpActionContext actionContext)
    if (HttpContext.Current != null && HttpContext.Current.User as CustomPrincipal != null)
    return;
    // TEMPORARY (need more robust solution): pushing batch request principal to a sub-request thread
    if (actionContext.Request.IsBatchRequest() && actionContext.RequestContext.Principal is CustomPrincipal)
    Thread.CurrentPrincipal = actionContext.RequestContext.Principal;
    return;
    This works fine. But we are not sure this is the right way to handle it. Does anybody know what is the recommended solution for the problem described?

    Hi Dmitry Marcautsan,
    According to your description, the issue is related to the ASP.NET Web API, I'd suggest you post
    here to get better support. 
    Thanks for your understanding.
    Best Regards,
    Amy Peng
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How many enterprise projects we can create in a single project web app site in project server 2013 enterprise?

    I have MS SharePoint 2013 Enterprise and MS Project Server enterprise installed in the same server,
    I have created project web app site 
    can anyone tell me that how many enterprise projects I can create in a single Project web app site
    what is the recommended number of enterprise project per project web app

    As I remember each project site is a sub site in a project Web app site collection.  That means you can have a maximum of 250,000 project sites before you run out of space in the site collection.  That's the boundary for sub sites in a single
    site collection for SharePoint 2013.  Project server doesn't have a specific limit.
    Paul Stork SharePoint Server MVP
    Principal Architect: Blue Chip Consulting Group
    Blog: http://dontpapanic.com/blog
    Twitter: Follow @pstork
    Please remember to mark your question as "answered" if this solves your problem.

  • Where is the Google Web APIs Developer's Kit and developer's license key???

    Hi!
    I'm trying to follow the web services tutorial on page 490 of the Oracle JDeveloper 10g Handbook (written in 2004 so it is a little dated). Part I of the tutorial is to register with Google and download the Google Web APIs Developer's Kit, but I can't find it anywhere (at least not with that name). Does anyone know where is it?
    On a related topic, this tutorial (http://www.oracle.com/technology/oramag/webcolumns/2003/techarticles/balusamy.html) talks about a Google developer's license key (Understanding Google Web APIs section), but again, when I created a Google account I did get a confirmation email, but no second email with no key. Where do I find this?
    TIA for any help.

    what type of application?
    Here is the basic of how to use a Web service in a JSF/ADF based application:
    http://www.oracle.com/technology/products/jdev/viewlets/1013/WebServicesAndADF_viewlet_swf.html
    and this section of the how-to shows you how to create a basic Java client:
    http://www.oracle.com/technology/obe/obe1013jdev/10131/devdepandmanagingws/devdepandmanagingws.htm#t6s1

Maybe you are looking for

  • FIREFOX 3.6 PROBLEM WITH STAY ON TOP BUT 3.5 WORKS FINE

    WHEN I USE FIREFOX 3.6 OR ANY VERSION OF THE 3.6 AND I SELECT STAY ON TOP (I HAVE A THIRD PARTY PROGRAM THAT ALLOWS THIS) AFTER I MINIMIZE THE WINDOW THEN IT WILL LOOSE THE STAY ON TOP COMMAND. ALTHOUGH WITH FIREFOX 3.5 VERSIONS IT KEEPS IT'S STAY ON

  • Windows 98 with NW Client 3.4

    Dear All, Most of Windows 98 users reported the NW Client always prompted the following message. Client32:Please wait while System retries request to <Server Name> To stop waiting, press Enter Netware will then return an error and try to reconnect in

  • ICCMP_BT_FOUP - How to call meth. 'DO_HANDLE_EVENT other Component/View?

    Dear Experts, when changing the field CONC_KEY-BTN in view BTSHeader in component ICCMP_BTSHEAD (Interaction Record Component) the method DO_HANDLE_EVENT of the view controller is called. The standard coding of the method is: method DO_HANDLE_EVENT.

  • Why not an Apple Store in Brussels

    Brussels the city where the most of the european office are located and still no Apple store located! Is Apple falling asleep? It could be that the aren't aware that the head of the  european community is located in Brussels in Belgium; it should be

  • Are there are no weblogic hosted web services on the internet?

    I want to find a weblogic hosted web service for a demo. But I can't find a single internet based example that is explicitly hosted on weblogic. Does anyone have an example web service I can use ? Surely BEA would benefit from publishing a few exampl