Question

This is the service:

public class InvoiceDetailsService : RestServiceBase<InvoiceDetails>
{
    public override object OnGet(InvoiceDetails request)
    {
        return new InvoiceDetailsResponse();
    }
}

And these are the service models:

[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; }
}

And this is the Invoice class, inheriting from Sharp Architecture's Entity class. (I have removed all the other properties trying to isolate the cause.) 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; }
}

I should be getting a serialized empty InvoiceDetailsResponse back to the browser.

The error I'm getting is this, which I don't get if Invoice is a simple POCO and not derived from Entity.

--TypeInitializationExceptionThe type initializer for 'ServiceStack.Text.Json.JsonWriter1' threw an exception.</Message><StackTrace> at ServiceStack.Text.Json.JsonWriter1.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) in e:\Desktop\Dev Projects\ServiceStack-master\src\ServiceStack.Common\ServiceModel\Serialization\JsonDataContractSerializer.cs:line 30 at ServiceStack.WebHost.Endpoints.Formats.HtmlFormat.SerializeToStream(IRequestContext requestContext, Object response, IHttpResponse httpRes) in e:\Desktop\Dev Projects\ServiceStack-master\src\ServiceStack\WebHost.Endpoints\Formats\HtmlFormat.cs:line 49 at ServiceStack.WebHost.Endpoints.Extensions.HttpResponseExtensions.WriteToResponse(IHttpResponse response, Object result, ResponseSerializerDelegate defaultAction, IRequestContext serializerCtx, Byte[] bodyPrefix, Byte[] bodySuffix) in e:\Desktop\Dev Projects\ServiceStack-master\src\ServiceStack\WebHost.Endpoints\Extensions\IHttpResponseExtensions.cs:line 190

Should I instead be creating a separate class for my service, and use a mapper? (It seems redundant to do so.) Why can't I use my Entities directly?

Was it helpful?

Solution

The innermost exception said that it was looking for Newtonsoft.Json version 4.5. The version I got with ServiceStack was 4.0. I used Nuget for the latest version of Newtonsoft.Json and the error went away.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top