Following the example in this article: http://blogs.msdn.com/b/yaohuang1/archive/2012/05/21/asp-net-web-api-generating-a-web-api-help-page-using-apiexplorer.aspx
I've set up everything to provide documentation for my Web API project but I'm running into an issue. When I try to use @api.HttpMethod
I get the error he describes about halfway through the article. He says you have to manually add a reference to the System.Net.Http
, Version=2.0.0.0 assembly in the web.config (even though it's in the References folder by default), but if you follow his example of adding the assembly the traditional way through the tag in web.config..... well you'll find that is no longer a valid tag in 4.5 and everything is done through AssemblyRedirects. I tried that but to no avail. Anyone having this issue or know how to help with the change in web.config? Did I miss a meeting?
Visual Studio 2012 MVC4 Web API project (not from Nuget, the final release shipped with VS2012)
Asp.Net MVC is used to create web applications that return both views and data but Asp.Net Web API is used to create full-blown HTTP services with an easy and simple way that returns only data, not view. Web API helps to build REST-ful services over the .
Provides a programming interface for modern HTTP applications, including HTTP client components that allow applications to consume web services over HTTP and HTTP components that can be used by both clients and servers for parsing HTTP headers. Commonly Used Types: System. Net.
The main conclusion is that one is not better than the other, and we shouldn't compare them since RestSharp is a wrapper around HttpClient. The decision between using one of the two tools depends on the use case and the situation.
Although ASP.NET Web API is packaged with ASP.NET MVC, it is easy to add Web API to a traditional ASP.NET Web Forms application. To use Web API in a Web Forms application, there are two main steps: Add a Web API controller that derives from the ApiController class. Add a route table to the Application_Start method.
Add the below configuration inside your Web.config file under <system.web>
node (assuming your app runs on .NET 4.5, targetFramework
attribute is set to 4.5):
<compilation targetFramework="4.5">
<assemblies>
<add assembly="System.Net.Http, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</assemblies>
</compilation>
Also add the below one at the root level under <configuration>
node:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
This should solve your problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With