2
votes

Iam new to service stack and have been strugling for hours, trying to make servicestak work for me. For now the major show stopper is that i cann't make the exception part work. I registered all plugins by the book and services work for both REST, Soap, CSV, XML and JSV. The project contains 4 basic test methods for crud operations on a customer object. When an error is thrown i do not get the expected error: ResponseStatus is not set and a generel error is generated. Can some one please help me find out why?

https://dl.dropbox.com/u/101619220/TestingServiceStack.zip

EDIT: Thanks for comment :)

I created a simple AppHost file:

namespace TestingServiceStack { public class AppHost : AppHostBase { public AppHost() : base("StarterTemplate ASP.NET Host", typeof(CustomersService).Assembly) { }

    public override void Configure(Container container)
    {
        Plugins.Add(new ValidationFeature());
        Plugins.Add(new RequestLogsFeature());

        SetConfig(new EndpointHostConfig
            {
                DebugMode = true, //Enable StackTraces in development
            });

        LogManager.LogFactory = new Log4NetFactory(true);

        JsConfig.EmitCamelCaseNames = true;
        JsConfig.DateHandler = JsonDateHandler.ISO8601;

        Routes.Add<GetCustomers>("/customers", "GET")
              .Add<GetCustomers>("/customers/{Id}", "GET")
              .Add<AddCustomer>("/customers", "POST")
              .Add<UpdateCustomer>("/customers/{Id}", "PUT")
              .Add<DeleteCustomer>("/customers/{Id}", "DELETE");
    }

    public static void Start()
    {
        new AppHost().Init();
    }
}

}

And a service:

namespace TestingServiceStack { public class CustomersService : Service { #region Logging

    private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

    #endregion

    public object Any(GetCustomers request)
    {
        GetCustomersResponse response = null;
        try
        {
            if (request.Id != "0")
                throw HttpError.NotFound("Id {0} throws error".Fmt(request.Id));

            response = new GetCustomersResponse {Id = request.Id ?? "notset", Name = "GetCustomers"};
        }
        catch (Exception ex)
        {
            Log.Error(base.RequestContext.Get<IHttpRequest>(), ex);
            throw;
        }

        return response;
    }

    public object Any(AddCustomer request)
    {
        return new AddCustomerResponse {Id = request.Id, Name = "AddCustomer"};
    }

    public object Any(UpdateCustomer request)
    {
        return new UpdateCustomerResponse {Id = request.Id, Name = request.Name};
    }

    public object Any(DeleteCustomer request)
    {
        return new DeleteCustomerResponse {Id = request.Id, Name = "DeleteCustomer"};
    }
}

}

And the exchanged objects are:

using System.Runtime.Serialization; using ServiceStack.ServiceInterface.ServiceModel;

namespace TestingServiceStack { [DataContract] public class GetCustomers { [DataMember] public string Id { get; set; } }

[DataContract]
public class UpdateCustomer
{
    [DataMember]
    public string Id { get; set; }

    [DataMember]
    public string Name { get; set; }
}

[DataContract]
public class AddCustomer
{
    [DataMember]
    public string Id { get; set; }

    [DataMember]
    public string Name { get; set; }
}

[DataContract]
public class DeleteCustomer
{
    [DataMember]
    public string Id { get; set; }
}

[DataContract]
public class GetCustomersResponse : IHasResponseStatus
{
    [DataMember]
    public string Id { get; set; }

    [DataMember]
    public string Name { get; set; }

    [DataMember]
    public ResponseStatus ResponseStatus { get; set; }
}

[DataContract]
public class UpdateCustomerResponse : IHasResponseStatus
{
    [DataMember]
    public string Id { get; set; }

    [DataMember]
    public string Name { get; set; }

    [DataMember]
    public ResponseStatus ResponseStatus { get; set; }
}

[DataContract]
public class AddCustomerResponse : IHasResponseStatus
{
    [DataMember]
    public string Id { get; set; }

    [DataMember]
    public string Name { get; set; }

    [DataMember]
    public ResponseStatus ResponseStatus { get; set; }
}

[DataContract]
public class DeleteCustomerResponse : IHasResponseStatus
{
    [DataMember]
    public string Id { get; set; }

    [DataMember]
    public string Name { get; set; }

    [DataMember]
    public ResponseStatus ResponseStatus { get; set; }
}

}

I use SoapUi to call the method GetCustomers that throws an error if id equals 0, and i would expect the ResponseStatus to be set, but it isn't. When calling from SoapUi i get the following error:

I have no clue how to get reponsestatus set proberly, any hints are appreciated.

3
Dumping your project like this is not helpful and just costs more time to the people you want to help you. Ask a specific, clear and concise question, include and paste relevant parts of your code and explain exactly what your problem is i.e. what you've tried and what you expected should happen. Know that support questions should be designed to build a knowledge base and to help others encountering similar problems. Just dumping your project doesn't help with any of this. Basically don't expect others to help if they aren't able to infer your problem from just the question description. - mythz
The question update doesn't go anywhere near far enough to be able to answer this question, Don't expect anyone to open your project so if we can't determine the issue from the question it's going to be ignored. An AppHost definition does not explain what the error is, what you've tried, what you expected to happen and what did happen. - mythz
Its my first post here and did it in 2 steps. Please let me know if information is missing. - user2237815
There's not much that needs to be known to ask a good question, just don't assume anyone else knows anything about your specific problem, include all relevant info and context and be clear with exactly what your problem is. - mythz
Iam not sure i understand your answer. Should I not expect ServiceStack to work with SoapUi - its simple pure soap exchange in this case? All works fine except the processing of the exception. I also read about the limitations to soap in servicestack, and as you see, i copied much of the code from there. I still would be very thank full if you could give me a hint to what iam missing here? - user2237815

3 Answers

2
votes

I registered all plugins by the book and services work for both REST, Soap, CSV, XML and JSV To echo @mythz it's much easier to answer direct questions with clearly stated problems with examples of errors or exceptions. My issue with statements/generalizations like above is that I don't know what 'by the book' means nor do I know your concept of working is (could be build succeeds, metadata page is displayed, etc)

ResponseStatus is not set and a generel error is generated.

In your CustomersService class it looks you are throwing an error (HttpError) and catching/logging it. The code will then proceed to return a null response. ServiceStack has native support for throwing of exceptions. If you add a throw into your catch (assuming you want to keep the catch for logging purposes) you should get a populated ResponseStatus.

        GetCustomersResponse response = null;
        try
        {
            if (request.Id != "0")
                throw HttpError.NotFound("Id {0} throws error".Fmt(request.Id));

            response = new GetCustomersResponse {Id = request.Id ?? "notset", Name = "GetCustomers"};
        }
        catch (Exception ex)
        {
            Log.Error(base.RequestContext.Get<IHttpRequest>(), ex);
            throw; //Let ServiceStack do its thing.
        }

        return response;

SoapUI

This change may fix the issue with soapUI but I'm unclear as what 'general error' you are receiving. I'm guessing the issue could be due to 'deserializing' a null response.

1
votes

ServiceStack doesn't support troubleshooting with 3rd party SOAP libraries or client proxies.

See WebServicesTests.cs for examples of exceptions in integration tests. For SOAP you also want to read up on ServiceStack's SOAP Support and its limitations

1
votes

We had an issue where ResponseStatus wasn't being populated - we'd decorated the Response DTO with DataContract/DataMember, but not the ResponseStatus property. Once we added that decoration, all was joyful.