OpenRasta 通过 JsonDataContractCodec 返回列表
假设我有一个如下所示的资源:
namespace OpenRastaApp.Resources
{
public class Foo
{
public string Bar { get; set; }
}
}
一个处理程序如:
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" };
}
}
}
和一个配置为:
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 按预期呈现:
{"Bar":"Baz"}
但是,/foos 根本不呈现。调试控制台显示消息“8-[2010-09-22 13:39:29Z]信息(0)未搜索响应编解码器。响应实体为空或已设置响应编解码器。”在返回之前我已经验证结果不为空。我也尝试过返回 Foo[],但有同样的错误。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
想通了。必须修改我的配置如下:
Figured it out. Had to modify my configuration as follows:
仅供参考,您还可以执行以下操作:
Just FYI, you could also have done the following: