I implemented a basic Web Api interface to Umbraco (v7.1.6)
Server code:
public class MemberController : UmbracoApiController { [HttpGet] public IEnumerable GetMembers(string countryCode) { return GSKTools.Server.Handlers.MemberHandler.GetMembers(countryCode); } }
Client code (console application):
using (var client = new HttpClient()) { client.BaseAddress = new Uri(serverProperties.BaseAddress); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = await client.GetAsync("Api/Member/GetMembers?countryCode=FI"); }
Code above works fine during first run. Second run from client causes always an internal server error. I have to restart Web site or do a clean build to get rid of an error
Response contains following information when it fails:
System.TypeLoadException: Inheritance security rules violated by type: 'System.Net.Http.Formatting.JsonContractResolver'. Derived types must either match the security accessibility of the base type or be less accessible.
at System.Net.Http.Formatting.JsonMediaTypeFormatter..ctor()
at System.Net.Http.Formatting.MediaTypeFormatterCollection.CreateDefaultFormatters()
at System.Web.Http.HttpConfiguration..ctor(HttpRouteCollection routes)
at System.Web.Http.GlobalConfiguration.<.cctor>b__0()
at System.Lazy`1.CreateValue()
at System.Lazy`1.LazyInitValue()
at Umbraco.Web.WebBootManager.InitializeResolvers()
at Umbraco.Core.CoreBootManager.Initialize()
at Umbraco.Web.WebBootManager.Initialize()
at Umbraco.Core.UmbracoApplicationBase.StartApplication(Object sender, EventArgs e)
Umbraco 7 Web Api and Internal Server Error
I implemented a basic Web Api interface to Umbraco (v7.1.6)
Server code:
Client code (console application):
Code above works fine during first run. Second run from client causes always an internal server error. I have to restart Web site or do a clean build to get rid of an error
Response contains following information when it fails:
And following lines appears to UmbracoTraceLog.txt
2014-10-23 09:14:39,243 [30] ERROR Umbraco.Core.UmbracoApplicationBase - [Thread 34] An unhandled exception occurred
What I am doing wrong? Configuration issue?
Shouldn't your API controller method be returning an IEnumerable of a specific type? eg.
publicIEnumerable<IMember>GetMembers(string countryCode)
Yes it should and actually is. Must be a copy-paste mistake:
is working on a reply...