Pregunta

My application makes an AJAX call to the route /{Lang}/cook to retrieve an rendered Razor partial.

In VS2012 via Cassini, I am able to get a response;

However, in Xamarin 4.2.3 (build 60), I get the following error: Failed to load resource: the server responded with a status of 405 (NotImplementedException)

http://127.0.0.1:8080/en-us/cook

Any ideas why the route works in one IDE, but not the other?

I am using Service Stack 4.0.12.0, with In-Memory caching. The system is being run in free/evaluation mode.

Here is a service method that uses caching:

Inside public class ScenarioService: Service

[DefaultView("cook")]
public object Get(CookScenario request)
{
    var cacheKey = GetCacheKey ("cook", request.Lang);

    return base.Request.ToOptimizedResultUsingCache (base.Cache, cacheKey, () => {
        CookScenarioResponse response = LoadJson<CookScenarioResponse>(request.Lang, "cook");
        return response;
    });
}

Inside AppHost.cs

public override void Configure(Funq.Container container)
{
    //Set JSON web services to return idiomatic JSON camelCase properties
    ServiceStack.Text.JsConfig.EmitCamelCaseNames = true;

    //Configure User Defined REST Paths

    container.Register<ICacheClient>(new MemoryCacheClient());

    this.GlobalRequestFilters.Add((request, response, requestDto) =>
    {

         var localizedReq = requestDto as LocalizedRequest;
         if (localizedReq != null)
         {
             Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentUICulture = new CultureInfo(localizedReq.Lang);
         }

    });
    Plugins.Add(new RazorFormat());

}

EDIT: I tried removing the ToOptimizedResultUsingCaching and the service for "/en-us/cook" worked fine; so, the issue is definitely an issue with the ToOptimizedResultUsingCaching in Service Stack 4.0.12.0 on Xamarin Studio 4.2.3 (build 60) on a Mac OS 10.7.5.

Here is the mono version info: Mono JIT compiler version 3.2.6 ((no/9b58377 Thu Jan 16 17:49:56 EST 2014)

Resolution 3/27/2014 1PM PST

After I grabbed the pre-release version (4.0.16) of ServiceStack I was able to confirm that in-memory caching now works on Xamarin 4.2.3 (build 60) against my Macbook pro laptop (OSX 10.7.5).

Thanks again for the help!

¿Fue útil?

Solución

I believe the error you are seeing is a shortcoming of Mono, and the XSP/fastcgi-server-4 host which is used by Xamarin Studio.

I previously experience the same problem with ToOptimizedResult/ToOptimizedResultUsingCache methods not working because they rely on a call to System.Web.HttpContextWrapper.GetService which has not been implemented in Mono.

See here for the relevant Mono source code:

public class HttpContextWrapper : HttpContextBase
{
    ...

    [MonoTODO]
    public override object GetService (Type serviceType)
    {
        throw new NotImplementedException ();
    }
}

I found the only way to work around this issue with Mono was to use a Self Hosted ServiceStack application because it uses System.Net.HttpListener which does not suffer from this issue. See my previous answer on this issue which describes this in more detail.


Fix:

A commit to ServiceStack has been made to address this issue, and it will be fixed in version 4.0.16

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top