WCF Service Application VS ASP.NET Web Application? - c#

I'm building a Web API to access my database. I would like to create a Single Page Application Website first then a iPhone, Android and Windows application. Classic.
My data and business layer are already finished.
First I decided to build a Json WCF Webservice. In Visual Studio I created a WCF Service Application. I modified the Web.config file to accept Json requests and implemented my interface and svc file.
After that I discovered ASP.NET Web Application with the Web API template. So I decided to change and to create a real web API with this full website structure.
Now I'm lost. What are the differences between these two possibilities to create a Web API?

A comparative from microsoft : http://msdn.microsoft.com/en-us/library/jj823172(v=vs.110).aspx
Personnaly, I prefer WCF because the datacontracts are generated in the case of SOAP Web Services with WSDL files.

Related

Web Api and web ui in same application/service

For my AngularJS web application I use Azure Service Fabric as my backend. For that I created a stateless web api service.
Do I have to put the frontend /client-side AngularJS code in the same application type or the same stateless service? Is it useful to create another stateless service for the web ui?
As others have mentioned, you can host your Angular web app anywhere you like; there are no restrictions imposed by Service Fabric in this regard.
That said, in your case a simple solution is to have your front-end web app and your web api in the same stateless service. Basically you treat this as a regular old ASP.NET MVC application, and ASP.NET MVC makes it fairly easy to have an API and web UI in the same MVC project. Here are a couple examples of this:
ASP.NET 5 MVC application with an API and a UI: https://github.com/Azure-Samples/service-fabric-dotnet-getting-started/tree/master/Services/Chatter
Single-page jQuery app with an API self-hosted with Katana: https://github.com/Azure-Samples/service-fabric-dotnet-management-party-cluster/tree/master/PartyCluster
As to the question of why do you need Service Fabric to host a front-end file. There are trade-offs here. Assuming the front-end is a web application that's meant to be part of a larger Service Fabric application - as it is in your case - it's nice to have everything in one place using one set of tools on the same SDK with the same deployment process hosted on the same cluster, rather than having a completely separate process, tools, SDK, and hosting environment for one part of your application. You also get all the Service Fabric goodness like rolling upgrades, health monitoring, high availability and auto failover, etc. The downside is that you don't get the super easy-to-use tools for web applications that come with, say, Azure App Service.

What tools/methods are used to consume WCF web services for Android?

I am designing an Android application which is supposed to connect to a server via WCF web service.
I have a WCF web service written in .NET 4.5 and it is a self-hosted web service. It has SOAP endpoint configuration and it is not a very complex service, however it does include some methods which return DTOs (Classes containing lists, other DTOs and value types).
Now the problem I am facing is that I wish to use some sort of tools to consume the web service definition and generate the proxy classes. I have been successful doing this with the help of Eclipse, but the resulting generated code uses alot of external libraries not available within Android.
Now my question is, what are the preferred tools/methods to consume WCF SOAP web services?
I found that using the following tool gave me the best generated code.
https://code.google.com/p/android-ws-client/
I do recommend this tool to anyone looking for consuming a WCF SOAP web service.

Create C# SOAP API Consumable by other Languages

I've been trying to find a tutorial on here, MSDN, and Google on how to implement my own SOAP API. I have an application written in C# that I want to be consumable by PHP so that calls from the web can interact with the application. How do I generate and tie a WSDL file to my application so that it can be communicated with over SOAP calls? Any suggestions?
I think for this you just need to create WCF service in .net that will allow you to consume server from any language.
Create an ASP.Net Web Services .wsdl file to communicate with the various applications. Host the Web Service on windows IIS server and configure the ports accordingly, then you can access the endpoints to whcih ever application you are using, using the address and the web method name.

ASP.NET Web Api as a standalone project in one solution

If i want to use WebAPI as a service to connect to multiple databases on different servers and retrieve the data that my MVC application will use what is the best way to do it?
I don't want do have ApiController(s) in the same project as my MVC project so do i need to add a new WebApi project (delete all except controllers and stuff that the template adds to have a clean project) that my MVC application will reference?
Here's the list of tutorials/blog posts i used to learn about WebAPI:
ASP.NET Web API - Screencast series with downloadable sample code
http://weblogs.asp.net/jgalloway/archive/2012/03/16/asp-net-web-api-screencast-series-with-downloadable-sample-code-part-1.aspx
Consuming ASP.NET Web API Service using HttpClient
http://debugmode.net/2012/03/03/creating-first-http-service-using-asp-net-web-api-part1-of-many/
http://debugmode.net/2012/03/07/consuming-asp-net-web-api-service-using-httpclient-part2-of-many/
CRUD operation using ASP.NET Web API and MVC4
http://www.dotnetglobe.com/2012/03/crud-operation-using-aspnet-web-api-in.html
http://www.dotnetglobe.com/2012/03/crud-operation-using-aspnet-web-api-in_28.html
Creating a .Net queryable client for ASP.Net Web API oData services
http://blog.petegoo.com/index.php/2012/03/11/creating-a-net-queryable-client-for-asp-net-web-api-odata-services/
Using HttpClient to Consume ASP.NET Web API REST Services
http://www.johnnycode.com/blog/2012/02/23/consuming-your-own-asp-net-web-api-rest-service/
Client side support with the ASP.NET Web API
https://msmvps.com/blogs/theproblemsolver/archive/2012/03/13/client-side-support-with-the-asp-net-web-api.aspx
Create and Consume ASP.Net Web API REST Services - MVC4
http://www.askamoeba.com/Opensource/Opensourcedetail/144/Create-and-Consume-ASP-Net-Web-API-REST-Services-MVC4
Building and consuming REST services with ASP.NET Web API using MediaTypeFormatter and OData support
http://robbincremers.me/2012/02/16/building-and-consuming-rest-services-with-asp-net-web-api-and-odata-support/
Using JSON.NET with ASP.NET Web API
http://blogs.msdn.com/b/henrikn/archive/2012/02/18/using-json-net-with-asp-net-web-api.aspx
Creating Custom CSVMediaTypeFormatter In ASP.NET Web API for Comma-Separated Values (CSV) Format
http://www.tugberkugurlu.com/archive/creating-custom-csvmediatypeformatter-in-asp-net-web-api-for-comma-separated-values-csv-format
Implementing CORS support in ASP.NET Web APIs
http://blogs.msdn.com/b/carlosfigueira/archive/2012/02/20/implementing-cors-support-in-asp-net-web-apis.aspx
How I see Web API
http://thedatafarm.com/blog/asp-net/how-i-see-web-api/
You may use a completely different project to host your Web API controllers. Yet in this case you need to think about the deployment.
Web API is just a web project. It will have its own config file. It will be likely that it will run in its own worker process (depending on how you deploy it).
So if you partition the Web API out, then you get more flexibility but you might end up duplicating a lot of config.
My advice is that, if you do, make sure both projects talk to the same base services projects. Partitioning can also make sense if this Web API might be used by third parties.

Calling ASP.net Web Service from C# Application

I have a question. How can i invoke a web service and get the result from a C# desktop application. I am making a desktop app and I want it to be able to connect to my online ASP.net web services. How is this possible?
In Solution Explorer, right-click your project node and select Add Service Reference.
Enter the URL where your service WSDL is located. This is usually the URL of the service itself.
This generates a strongly-typed proxy class in a new Services References folder in your project.
Write code in your desktop app to instantiate the proxy class and invoke methods on it. The rest works like magic. :)
AB Kolan was also correct, but Add Web Reference uses the old-style web services framework whereas Add Service References uses the new WCF stack. Important note: It is not required that the service itself use WCF for you to use WCF on the client side. WCF on the client is typically the best choice for any service, provided you can take a dependency on .NET 3.0 and above.
Add a Web Reference to the webservice in your Desktop App project reference. Doing so would generate a Proxy for the Webservice called Reference.cs
You can access your webservice using the proxy.
This is possible the same way that you access web services from any other type of application, be it an ASP.NET page, a class library or windows service.
For an explanatory tutorial on the subject, see Accessing a Web Service from a Desktop Application.
Will get help how to create a webservice and consume that service:
http://www.c-sharpcorner.com/UploadFile/0c1bb2/consuming-web-service-in-Asp-Net-web-application/
Thanks

Categories

Resources