Moving angularJS site to Visual Studio? - angularjs

So in my quest to learn front-end development (doing server side, WCF, etc for the past 4-5 years), I managed to create a simple little movie app just using javascript and html. When I created this app, I was using Sublime Text and since I'm a .NET developer, I'd like to move this site over to Visual Studio and actually wire it up to WebAPI or MVC and start talking to a database.
What is the best way to move over a pure html/javascript/css site into Visual Studio and wiring it up for db connectivity? I thought about just creating a web site project in a solution and start wiring it up to a BLL and DAL layer but I didn't know if that was ideal or not.
Any help would be appreciated.
Thanks!

IMO Your best bet is to create an empty WebAPi2 project in VS and create a folder called 'app' that you will move your Angular files into.
Right click your project and go to the Web tab. Set the start page to whatever HTML file is your main page.
You should now be able to just F5 and run the application. Then start creating WebApi controllers for your data layer and you should just able to hit the API from localhost/api (or whatever you designate in your routes)

AngularJS should be completely independent of the server language (php, c#) and server (nginx, apache, IIS) you run it on.
I have worked on angular projects that talk to C# WCF services and are hosted on IIS just fine. You best bet is to create restful services in WCF and use angular services and factories to pull that data into the client angular app.
I think the best place to start would be the $http service of Angularjs.
https://docs.angularjs.org/api/ng/service/$http

Related

Visual Studio Solution with Two Projects Hosted on Azure

This is the first website that I am trying to publish to make live and rather lost on how exactly I should go about it. I have a Solution in Visual Studio 2015 that is separated into two projects. My AngularJS front end is in one project and I have a web api back end that communicates with a SQL DB to fill http request from the front end. I have been testing to make sure that everything works by launching from visual studios and setting them to communicate with localhost:. Everything works fine when I do this.
I now want to host this project as an Azure web app. I have tried downloading the publish settings and hitting publish for each of the projects in visual studio. Visual Studio tells me that my solution has been successfully deployed, but when visiting the site, all I get is a "Server Error in '/' Application".
I do not really know how to go about doing this. Any help would be greatly appreciated.
The problem is that each time you're publishing your project to Azure it overrides previously deployed project. So if you're deploying you client project last it will override previously deployed API and vise versa.
There are several ways to do achieve what you want.
First is to have two Azure Web Apps, one for client and one for API. But it will lead to cross domain requests.
Or you can do like pre-deploy event on your side before publish which will combine your API and Client in one "project". There are also several ways you can do this. You can reference one project from another and build API and Client proejcts in one folder or have a pre-deploy event which will merge API and Client. Also, keep in mind that you will have to merge your web.config files. Also not the best way.
Or the best one. Just create a several virtual directories in your Azure Web App I would prefer this one.

ASP.NET web api SPA project layout

I am building a proof-of-concept line-of-business Single Page App. I want to use ASP.NET web api for the REST service layer, and Backbone.js and Require.js on client. I would like to use modular structuring of js files and templates (Require.js) so the source code of the app would not end up in one html page.
I havent found an example how to lay out the project in Visual Studio, and what project type should I choose. Should Web Api be in one project, and web application in another, or should it be mixed. Any advice or best practice would be very appreciated.
Thanks!
What I did previously for the same goals was to put the WebApi and Web application in the same project. It makes thigs easier from the point of view that you will everything set up when you create the project in Visual Studio.
There is a slight problem in having the webapi in a different project: since you have to put that on a separate hosting or eventually on the same hosting but bound on a different port or virtual directory, it may need some time setting up IIS... eventually in the past we used the Url rewrite module to redirect calls from the Web App to the Web Api application. There may be simpler settings but again it will require a bit of time, depending on your confidence in setting up IIS...
For starter/proof of concept probably having everything on the same application will make things smoother. You may want to keep Domain Models and DB access in separate projects so if eventually you end up splitting the WebApi from the Web App you can still reference those two without problems.
In the end, the Web Application will only have one controller with one action (Home/Index maybe) and this will be the point of contact that will deliver all your html/css/js to the client. Being a SPA, everything from now on will be managed by Backbone on the client (navigation too), with the occasional call to your JSON Web Api endpoints to get and post data.

ServiceStack as a ServiceLayer for MVC, WPF, WP7-8

after bumping into ServiceStack i would like to explore the option to have ServiceStack as a ServiceLayer for my existing MVC4 Project. The goal is to create a servicelayer for all other platform options like wpf, windows phone...
My main issue is the existing mvc project and the need to continue to use the SimpleMembershipProvider. Is it possible to move all code of the default AccountController to the ServiceStack ServiceLayer and call it from the AccountControler (WebSecurity Class)? Has someone tried something like this or should i dump this code and start a ServiceStack specific Security Class?
Regards,
S. Mantziaris
The first part on service layer is in http://nuget.org/packages/ServiceStack.Host.Mvc/ (adding it to your MVC4 project via NuGet almost instantly gives your a working service layer, just run and check yourhost.com/api/metadata).
https://github.com/ServiceStack/SocialBootstrapApi gives you a detailed example how to do authentication and authorization the ServiceStack way.
Check these two answers on how to integrate ASP Membeship and ServiceStack:
https://stackoverflow.com/a/8715958/801189 and https://stackoverflow.com/a/15078308/801189

"Calls to the web service will fail..." Once Again

Last year someone reported encountering this problem ("The Silverlight project you are about to debug uses web services. Calls to the web service will fail unless the silverlight project is hosted in and launched from the same web project that contains the web services.") and accepted the answer to "set the web project which hosts the Silverlight application to be your startup project."
I'm seeing the same message, but think the solution might have to be different. I am building in VS 2010 a Silverlight application to access the Google Weather API, with VB as the code-behind. The API will return a XML file with data for the specified city (ex., "http://www.google.com/ig/api?weather=london,england"). The Solution Explorer only shows my VB/Silverlight project ("GetWeather"), and the Project Properties dialog box shows the Startup Object as "GetWeather.App" -- the only choice. I'm trying to use a WebClient object to make the call and an XDocument object to parse the return. But I repeatedly get the above error message, with no other result. What am I doing wrong?
Thank you in advance!
I would add a simple Web project and configure it to host the Silverlight app. You'll need to host the app somewhere anyways, so why not create a stub ASP.NET application in your solution? The easiest way is to create a new Silverlight app solution selecting an ASP.NET web project as the host, and then copying your existing code to that solution. Then you should set the web project as the startup one. This should make debugging a lot easier.
Besides, do remember to configure the client access policy to enable cross-domain calls. Check out this article

Send simple data from wp7 to winforms application

I want to send simple data (geolocation data to be precise) from Windows Phone 7 application to a windows forms application and use it, as I'm a total beginner in this field I don't know which tools to use.
I searched about wcf services and tested this method but there's some issues: the data is sent from the phone application but isn't sent to the winforms application (guess something is missing)
If your know how to do this in a quick way, or have good tutorials I'll be thankful.
EDIT
I found this tutorial, it show how to connect directly wp7 application and desktop application without using sockets neither wcf service, I'm wondering if it is really works if the application isn't in localhost.
the like for the tutorial: wp7 tutorial
I had a similar problem and so I created a REST/JSON WCF service hosted in IIS with AppHarbor to provide the data. There's hundreds of ways to do it (Ruby/Heroku, etc..), but that particular one fits well within the Microsoft stack. I also needed to share route data and I used the WCF service to wrap the BingMaps services so that route computations are cached and shared. Considering that I had already created a local model, moving it out of my phone project into a service took less than a few hours (including the usual config hiccups, and forgetting to add the appharbor user to my bitbucket repo).
Consuming the service from WinForms (or any client) shouldn't be an issue as the service knows nothing about the client implementation.
Here's a tutorial from code project. REST WCF Service with JSON
I think you would need to implement some sort of server side solution which you could upload to on your Windows Phone and download from on your Windows Form application. This could be achieved using a WCF service which was connected to a server side database.
Another option would be to use sockets and communicate directly with your WinForms application. Check this tutorial on how to use basic sockets on WP7.

Resources