I would like to use ASP.NET WebApi inside a SharePoint 2013 farm solution.
I know it is not supported out-of-the-box, but I found SignalR can be run by means of a simple HttpModule, so I was wondering whether a similar appoach could be used.
Thanks in advance, Rich
UPDATE June 2013
Made it working by reworking the HTTP Module shown in the mentioned post:
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "kms2013/api/{controller}/{action}",
defaults: new { }
);
config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
config.Services.Replace(typeof(IAssembliesResolver), new SPAssemblyResolver());
HostingEnvironment.RegisterVirtualPathProvider(new WebAPIVirtualPathProvider());
SPAssemblyResolver
public class SPAssemblyResolver : IAssembliesResolver
{
public ICollection<Assembly> GetAssemblies()
{
return new List<Assembly> { Assembly.GetExecutingAssembly() };
}
}
WebAPIVirtualPathProvider
Same as SignalRVirtualPathProvider shown in the post.
NEW ISSUE
The only problem with this approach is ScriptResource.axd and WebResource.axd now break when SP references them in a page. I tried to add an ignore route:
RouteTable.Routes.Add(new Route("{resource}.axd", new StopRoutingHandler()));
But I keep getting 401 Unauthorized. Removing the module clears the error, so I guess we're still lacking one last piece of the puzzle.
SharePoint offers a rich set of APIs that can be consumed in various ways. This article outlines what options you have, how they work and what their advantages and disadvantages are.
SharePoint includes a Representational State Transfer (REST) service that is comparable to the existing SharePoint client object models. Now, developers can interact remotely with SharePoint data by using any technology that supports REST web requests.
Yes, the same approach should work.
Create a web api project and check the app init part - then follow my blog post you referenced already.
Btw: Ask at sharepoint.stackexchange.com - maybe someone has a better solution.
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