1

I have created a REST service in ServiceStack, but when I call it with the REST URL, it doesn't deserialize the JSON I post the service into my request object. If I use the default URL or supply the parameters in the query string it works fine.

My request object:

[Route("/myservice", "POST")]
public class MyRequestObject
{
    public string MyString { get; set; }
    public int MyInt { get; set; }
}

My Service:

public class MyService : Service
{
    public object Post(MyRequestObject request)
    {
        return new
            {
                MyString = request.MyString,
                MyInt = request.MyInt
            };
    }
}

And the json I post to the service:

{"myString": "abc", "myint": 42}

My REST URL is /api/myservice and the default URL is /api/json/asynconeway/MyRequestObject. I have verified that the service get's called with both the REST and default URL.

Thanks a bunch for your input.

Success headers

Request

POST /api/json/asynconeway/MyRequestObject HTTP/1.1
Host: bd.local
Connection: keep-alive
Content-Length: 32
Origin: chrome-extension://aejoelaoggembcahagimdiliamlcdmfm
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.79 Safari/537.4
Accept: application/json
Accept-Encoding: gzip,deflate,sdch
Accept-Language: da-DK,da;q=0.8,en-US;q=0.6,en;q=0.4
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

Response

HTTP/1.1 200 OK
Cache-Control: private
Content-Type: application/json; charset=utf-8
Server: Microsoft-IIS/7.5
COMMERCE-SERVER-SOFTWARE: Microsoft Commerce Server, Enterprise Edition
X-Powered-By: ServiceStack/3,914 Win32NT/.NET
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Mon, 01 Oct 2012 10:32:37 GMT
Content-Length: 29

Error headers

Request

POST /api/myservice HTTP/1.1
Host: bd.local
Connection: keep-alive
Content-Length: 32
Origin: chrome-extension://aejoelaoggembcahagimdiliamlcdmfm
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.79 Safari/537.4
Accept: application/json
Accept-Encoding: gzip,deflate,sdch
Accept-Language: da-DK,da;q=0.8,en-US;q=0.6,en;q=0.4
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

Response

HTTP/1.1 200 OK
Cache-Control: private
Content-Type: application/json; charset=utf-8
Server: Microsoft-IIS/7.5
COMMERCE-SERVER-SOFTWARE: Microsoft Commerce Server, Enterprise Edition
X-Powered-By: ServiceStack/3,914 Win32NT/.NET
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Mon, 01 Oct 2012 10:30:38 GMT
Content-Length: 11
7
  • You're not trying to make a GET request right? How are you POST'ing to it? does it work when you remove the "POST" verb? Commented Oct 1, 2012 at 9:47
  • No I am making a POST. I've tried via jQuery and Dev HTTP Client for Chrome - both works fine with the default URL. Does not work without the POST verb either. Commented Oct 1, 2012 at 9:54
  • It should work, but there's not enough information to determine the root cause. Ideally we'd want a stand-alone failing test at github.com/ServiceStack/ServiceStack/issues - but if you supply your Request / Response HTTP Headers (success + failure) that might show the issue Commented Oct 1, 2012 at 10:25
  • 1
    Is there an answer to this? Commented Jan 5, 2013 at 23:21
  • 1
    No haven't found out yet (other than using the default urls). Commented Jan 9, 2013 at 8:17

1 Answer 1

1

The issue could be in the code that makes the POST. Is the data json stringified, e.g.:

JSON.stringify({"myString": "abc", "myint": 42})
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.