简体   繁体   中英

Cannot get body of POST from Nancy REST server embedded in Unity game

I'm trying to set up a route for a Nancy POST, where I wish to submit an object in Json format, and use this to trigger an event in the Unity runtime - what I thought should be fairly standard stuff.

I thought that by following the example in NancyFX : Deserialize JSON I would be able to bind the body of the request to an object and then use that elsewhere, however I am actually getting this rather mysterious error:

Error CS1061: Type 'server.RESTServer' does not contain a definition for 'Bind' and no extension method 'Bind' of type 'server.RESTServer' could be found (are you missing a using directive or an assembly reference?) (CS1061) (server)

This is the relevent section from the offending source:

using Nancy;

namespace server
{
    public class RESTServer : Nancy.NancyModule, RESTInterface
    {
        public class LevelInfo
        {
            public string index;
        }
        public RESTServer ()
        {
            Delete ["/current/level"] = _ => 
            {
                UnloadLevel();
                return HttpStatusCode.OK;
            };
            Get ["/current/level"] = _ => Level;
            Post ["/current/level"] = _ => 
            {
                LevelInfo body = this.Bind<LevelInfo>(); //This is the offending line
                // snip rest of implementation
            }
        }
    }
}

My Mono/Monodevelop version info is on pastebin here , and the Assembly Browser shows this, also linked on pastebin, for Nancy.

I don't generally do much .net development so I'm sure it's something really simple, but I've already lost an afternoon trying to resolve this issue... Any help would be much appreciated.

Bind<> is extension method in Nancy.ModelBinding namespace.

You need using Nancy.ModelBinding;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM