Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Returning JSON from Web Service
Message
From
22/05/2014 09:32:07
 
 
To
22/05/2014 07:36:03
General information
Forum:
ASP.NET
Category:
Web Services
Environment versions
Environment:
C# 4.0
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01600242
Message ID:
01600455
Views:
36
>>I see three recommendations to switch to WebApi - we can't all be wrong :-}
>>
>>One suggestion - go for the newer 'Attribute Routing' - it's far more flexible and REST friendly than the older convention based approach.
>>
>>http://www.asp.net/web-api/overview/web-api-routing-and-actions/attribute-routing-in-web-api-2
>
>Go on, just throw in more stuff for me to understand, why don't you? :)

:-}
Just thinking that if you're just starting with WebApi you'll need to understand the routing system - so you may as well learn the attribute routing approach rather then the older way.

The old 'convention based' approach used the name you gave to the C# method to work out where to route things. With attribute routing you can specify whatever route you want. e.g.:
[HttpPost]
        [Route("t2/customers/add")]
        public HttpResponseMessage ThisMethodNameDoesntMatter(Customer customer)
        {
            // Do whatever
            return Request.CreateResponse(HttpStatusCode.OK);
        }
>
>I've got a Web Api example to work! Had to get VS 2013 and update to Web Api 2 to get it to work, but it looks like it works properly, so now I need to see if I can do this to use the business objects I created or if I'll need to create Models and controllers to pull my data out of the database (and post it back after being edited).

You should just be able to return the same object as you were in the web service.....
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform