Can I call a REST webservice an 'XML webservice'? - asp.net-mvc

Since REST services do not require XML, but we can use it with XML so can I call it a XML web service?
I'm doing my home work with the requirement that:
Using ASP.NET MVC
Provide an XML Web service
I was thinking about SOAP, but REST is more simple for me and I found alot of tut for REST with ASP.NET MVC rather than SOAP (They now all telling me about WCF...)
If REST is not an XML web service, please show some basic document about SOAP (or any thing else that call XML web service) with ASP.NET MVC!

Take a look at WCF Web Api. REST does not imply any particular format. A good REST service will allow you to set the Accept Header: json, xml, so on. E.g.: "accept" : "application/json"
Here is a good post on how to achieve this with WCF Web Api.

You can simply add a Web Service into your MVC application. You must take care about exclude "*.asmx" from your routes.
I.E:
routes.IgnoreRoute("{resource}.asmx/{*pathInfo}");

Related

Web Api Performance gain over MVC

I have a MVC web application and I make some ajax calls from the client to get back json data. Right now I just use MVC Action methods to return this data. I was wondering if I should be using the ASP.Net Web Api for these.
I understand that if I was building a REST solution I should be using it.
But in this case would it be justified to add the extra complexity? Is there any speed gain? I don't really need the Content Negotiation feature or the OData Support.
According to the post here (and the benchmark it references), Web API is a bit faster. Web api performance?
ASP.net Web api support both JSON and xml. Web Api is for implement rest web service on top of MVC application. It would add extra complexity for the application but you implement web api related method in separate controller.
Rest web services are usually faster than Normal SOAP web services.
In your case if your clients are just a web client no need to implement web services. But If you need to share service for different client (widows applications, windows services, third party applications) implement rest service using web API

How does web API and MVC work together?

How does MVC and web API work together in an application?
Are you supposed to use javascript binding (with knockout.js and ajax calls) and just use MVC for the actual container page?
Or do you call web API from the MVC controller (like a WCF service layer)?
The integration of MVC and web API just isn't clear to me.
Should I use Web API if I regulary require HTML to be returned (i.e. I want to work with Partials)?
I'd like to use web API so I can scale my app though (return HTML from one side, but remain with an API that can return/process XML)!
Thanks for clearing it up :)
This picture below from the link explains clearly how MVC and Web Api work together:
Technically, you can call from MVC to Web API, but it is not really the best practice since:
Calling from MVC to Web API will across the network (distribution), this makes your application more complex.
Web Api is REST Api, it is not like WCF which is heavily SOAP Api (although WCF support REST Api). So, from JavaScript you can call the Web Api easier using ajax.
Here's how I set up my latest MVC and Web API application: There's the regular model layer (*M*VC) and I have created a service layer for the business rules. The controllers of my MVC application call the service layer to process data from and to the views.
My Web API application is a external interface to the methods on the service layer, therefore both the controllers on the MVC application and on the Web API application call the service layer. I hope this helps.

why asp.net MVC controllers are not considered as RESTful web service

I have an asp.net web application, now let say a user send a POST action method to the application using following URL Myapplication.com/Customer/Edit/120, then this URL will update the customer who have ID=120 with the data sent.
So this is the same as calling a web service, since you are integrating with the application (in this case Update a customer) using URLs, so why this is not consider as having a RESTfull web service!
What exactly is a web service ? And how do you differentiate between a web page and web service.
These are just different terms of retrieving some Resource. Either with Web Service or Web Page, you are just requesting for a resource. The representation is fixed for web page i.e its always HTML. If from my web service instead of returning Json or XML , if it start serving HTML would then make it a web page ?
I think the whole concept of web service came with SOAP world. With Rest there is nothing as web service or web page. There are mere different representation for a resource(json, xml, html, image).
Further to answer your
so why this is not consider as having a RESTfull web service!
Microsoft has launched Asp.Net Web API, which is nothing but pure MVC to serve content.

asp.net mvc controller method -> soap web service

I am quite familiar with ASP.NET MVC and know that a controller’s method can respond with XML and JSON apart from other things (i.e. behave like a restful webservice). I am just wondering whether I can make a controller method behave like a soap web service which responds with a SOAP XML response to a POST request? Maybe it is just question of responding with XML but this would be more like a restful web service. I want to avoid having to implement a separate web service project if possible. Any feedback would be very much appreciated. Thanks.
Christian
You don't need to implement a separate web service project. All you need is to add a WCF service endpoint (.svc file) to your current web project. Also you are saying that you expect SOAP response after a GET request which of course doesn't make much sense because in the SOAP specification requests should be POST.
I believe your thought is to create a single deployable MVC Web Application that can respond to both SOAP requests and RESTful requests (maybe even more?). I have thought about this myself, however there is no point in re-inventing WCF as it can do both without any additional programming. The ASP.Net MVC assemblies were not designed to function as a web service, and although it can, probably shouldn't be when other technologies exist that were designed specifically for that purpose.

How to use SOAP in asp.net mvc

A 3rd party site sends its notifications after my web application has completed some action in order to notify me of its success. Receiving a notification item requires a response back to the 3rd party server (URL) with the a containing the value "accepted".
I have never user SOAP and with the basic info found I'm a bit lost for the case of asp.net mvc. Are there any good links showing the principle of receiving and sending SOAP responses?
Tutorials / information may be presented in other languages such as java, asp.net (classic) or something. I need to get a general idea since googling on SOAP has not given me anything for the past few hours.
You need to learn a little about WCF. See the WCF Developer Center, especially the Beginners Guide.
What you want is to create a simple WCF service that corresponds to the WSDL that they will give you. You will need to implement only the operation (method) that they will call to notify you. You can host a WCF service in IIS along with the rest of your application.
The issue will be how to correlate the notifications with the page you're on in your MVC application.
I don't think this is specific to ASP.NET MVC really. If you have a WSDL for their web service, just use that to generate stub classes using either wsdl.exe or by adding a web reference to your project, then call the web service from your controller.
If I remember correctly SOAP is basically xml requests and responses.
You might want to look into WSDL (Web Service Definition Language) to avoid having to deal with raw data, and you would likely find a great deal of tutorials on wsdl as well.

Resources