tags:

views:

33

answers:

1

Suppose I have a resource like below:

namespace OpenRastaApp.Resources
{
    public class Foo
    {
        public string Bar { get; set; }
    }
}

a handler like:

namespace OpenRastaApp.Handlers
{
    public class FooHandler
    {
        public object GetAll()
        {
            ArrayList foos = new ArrayList();
            foos.Add(new Foo() { Bar = "Hello," });
            foos.Add(new Foo() { Bar = " world!" });
            List<Foo> result = new List<Foo>(foos.ToArray(typeof(Foo)) as Foo[]);
            return result;
        }
        public object Get(int id)
        {
            return new Foo() { Bar = "Baz" };
        }
    }
}

and a configuration as:

namespace OpenRastaApp
{
    public class Configuration : IConfigurationSource
    {
        public void Configure()
        {
            using (OpenRastaConfiguration.Manual)
            {
                ResourceSpace.Has.ResourcesOfType<Foo>()
                    .AtUri("/foos")
                    .And.AtUri("/foos/{id}")
                    .HandledBy<FooHandler>()
                    .AsJsonDataContract();
            }
        }
    }
}

/foos/1 renders as expected with:

{"Bar":"Baz"}

however, /foos does not render at all. The debug console shows the message "8-[2010-09-22 13:39:29Z] Information(0) No response codec was searched for. The response entity is null or a response codec is already set." I've verified that result is non-null before returning. I've also tried returning a Foo[], but that had the same error.

A: 

Figured it out. Had to modify my configuration as follows:

namespace OpenRastaApp
{
    public class Configuration : IConfigurationSource
    {
        public void Configure()
        {
            using (OpenRastaConfiguration.Manual)
            {
                ResourceSpace.Has.ResourcesOfType<List<Foo>>()
                    .AtUri("/foos")
                    .HandledBy<FooHandler>()
                    .AsJsonDataContract();
                ResourceSpace.Has.ResourcesOfType<Foo>()
                    .AtUri("/foos/{id}")
                    .HandledBy<FooHandler>()
                    .AsJsonDataContract();
            }
        }
    }
}
takvam
Yes, we should really update the documentation. Lists of things and things are two different resources. We should at least have a warning / debug info to let people know
serialseb
Another option would be to use a list in either situation. That is the path I have started down, at least.
pc1oad1etter