ServiceStack(これはすばらしいです)を使用して簡単なRestサービスを構築しました。これは、キー値のペアのリストを返します。私のServiceStackサービスが例外をスローするのはなぜですか?
私のサービスは、次のようになります。
public class ServiceListAll : RestServiceBase<ListAllResponse>
{
public override object OnGet(ListAllResponse request)
{
APIClient c = VenueServiceHelper.CheckAndGetClient(request.APIKey, VenueServiceHelper.Methods.ListDestinations);
if (c == null)
{
return null;
}
else
{
if ((RequestContext.AbsoluteUri.Contains("counties")))
{
return General.GetListOfCounties();
}
else if ((RequestContext.AbsoluteUri.Contains("destinations")))
{
return General.GetListOfDestinations();
}
else
{
return null;
}
}
}
}
私の応答は次のようになります。
public class ListAllResponse
{
public string County { get; set; }
public string Destination { get; set; }
public string APIKey { get; set; }
}
と、次のように私は、残りのURLをマップした:
.Add<ListAllResponse>("/destinations")
.Add<ListAllResponse>("/counties")
呼び出すときサービス
Iは、(サービスの最初の行にブレークポイントがヒットされていない)は、この例外を受け取る:オブジェクトのインスタンスに設定されていない
とNullReferenceExceptionオブジェクト参照。 (ServiceStack.Common.Web.HttpResponseFilterのServiceStack.Text.XmlSerializer.SerializeToStream(Object obj、ストリームストリーム))。 <GetStreamSerializer> b_ ServiceStack.Common.Web.HttpResponseFilterの3(IRequestContext r、Object o、Stream s)。 < >c _DisplayClass1。 < ServiceStack.WebHost.Endpoints.Extensions.HttpResponseExtensions.WriteToResponseでGetResponseSerializer > b__0(IRequestContext httpReq、オブジェクトDTO、IHttpResponse httpRes)(IHttpResponse応答、オブジェクト結果、ResponseSerializerDelegate DEFAULTACTION、IRequestContext serializerCtx、バイト[] bodyPrefix、バイト[] bodySuffix)
例外は関係なく、私は任意の呼び出しのパラメータが含まれているか否かのスローされます。私は同じプロジェクトで同じ行に沿っていくつかの他のサービスを作成しています。誰かがこれが意味することについて正しい方向に私を向けることができますか?
本当にありがとう、私は本当に努力を感謝します。私は実際に自分自身でサービスを書き直しました。私はあなたが提案したラインに沿って広範にしたと言ってうれしく思います。また、私の回答にResponseStatusを含めました。あなたの答えはhttp://stackoverflow.com/q/4692313/20048です – Simon