这是服务:
public class InvoiceDetailsService : RestServiceBase<InvoiceDetails>
{
public override object OnGet(InvoiceDetails request)
{
return new InvoiceDetailsResponse();
}
}
这些是服务模型:
[DataContract]
[Description("Invoice Details web service.")]
[Route("/invoicedetails")] //Optional: Define an alternate REST-ful url for this service
[Route("/invoicedetails/{Id}")]
[Route("/invoicedetails/{Id*}")]
public class InvoiceDetails
{
public string Id { get; set; }
}
public class InvoiceDetailsResponse : IHasResponseStatus
{
public InvoiceDetailsResponse()
{
this.ResponseStatus = new ResponseStatus();
}
public Invoice Invoice { get; set; }
public ResponseStatus ResponseStatus { get; set; }
}
这是 Invoice 类,继承自 Sharp Architecture 的 Entity 类。(我已经删除了所有其他属性,试图找出原因。)http://code.google.com/p/sharp-architecture/source/browse/trunk/src/SharpArch/SharpArch.Core/DomainModel/Entity.cs
public class Invoice : Entity
{
public virtual DateTime Date { get; set; }
public virtual Double AmountPaid { get; set; }
}
我应该将序列化的空 InvoiceDetailsResponse 返回到浏览器。
我得到的错误是这个,如果 Invoice 是一个简单的 POCO 并且不是从实体派生的,我不会得到这个错误。
--TypeInitializationException 'ServiceStack.Text.Json.JsonWriter 的类型初始化器
1' threw an exception.</Message><StackTrace> at ServiceStack.Text.Json.JsonWriter
1.WriteFn() at ServiceStack.Text.Json.JsonWriter.GetWriteFn(Type type) at ServiceStack.Text.JsonSerializer.SerializeToString(Object value, Type type) at ServiceStack.Text.JsonSerializer.SerializeToString[T](T value) at ServiceStack.ServiceModel.Serialization.JsonDataContractSerializer.SerializeToString[T](T obj) 在 e:\Desktop\Dev Projects\ServiceStack-master\src\ServiceStack.Common\ServiceModel\Serialization\JsonDataContractSerializer.cs:ServiceStack.WebHost 的第 30 行。 Endpoints.Formats.HtmlFormat.SerializeToStream(IRequestContext requestContext, Object response, IHttpResponse httpRes) 在 e:\Desktop\Dev Projects\ServiceStack-master\src\ServiceStack\WebHost.Endpoints\Formats\HtmlFormat.cs: 第 49 行在 ServiceStack.WebHost .Endpoints.Extensions.HttpResponseExtensions.WriteToResponse(IHttpResponse 响应,对象结果,ResponseSerializerDelegate defaultAction, IRequestContext serializerCtx, Byte[] bodyPrefix, Byte[] bodySuffix) 在 e:\Desktop\Dev Projects\ServiceStack-master\src\ServiceStack\WebHost.Endpoints\Extensions\IHttpResponseExtensions.cs:line 190
我是否应该为我的服务创建一个单独的类并使用映射器?(这样做似乎是多余的。)为什么我不能直接使用我的实体?