ServiceStack DELETE request is default object, POST works fine

I have a DTO coming from the Javascript client. When I try to send with deleteFromService the request object is empty (looks like it was just new-ed up). If I change the method to postToService the request object is populated properly.

I am using the 3.9 API. I am at a loss here.

Service:

public object Post(Order request)
{
    return _orderRepository.InsertOrder(request);
}

public object Delete(Order request)
{
    _orderRepository.DeleteOrder(request.Uuid);
    return true;
}

JS:

//Fails
serviceClient.deleteFromService("order", order, function () { }, deleteFailed);
//Works
serviceClient.postToService("order", order, function () { }, deleteFailed);

Update:

I found the issue in the ServiceStack source code. It is treating a DELETE like a GET and creating the request object instead of the body, like it does for a POST.

if (httpMethod == HttpMethods.Get || httpMethod == HttpMethods.Delete || httpMethod == HttpMethods.Options)
{
    try
    {
        return KeyValueDataContractDeserializer.Instance.Parse(queryString, operationType);
    }
}

The problem with doing this, is that the ServiceStack JS client creates the DELETE request using the same logic as the POST, by stuffing the data you send it into the body (technically the jQuery XHR data prop), meaning there is no way for the server to get the message the client is sending.

Am I reading this right? Is the JS client's delete broken?


我重写了servicestack.js客户端在选项var初始化之前在P.Send函数中添加以下行...

if (ajaxOptions.type === "DELETE") {
    requestUrl = requestUrl + "?" + decodeURIComponent($.param(request[webMethod]));
}

A DELETE message should not carry a message body, meaning you are only allowed to pass parameters to the DELETE request in the url (ie like the ID of the object you want to delete). So, besides what ServiceStack does, you should never send a DTO in a DELETE request.

See this related question: Is an entity body allowed for an HTTP DELETE request?

链接地址: http://www.djcxy.com/p/11782.html

上一篇: IISExpress ClientCertificate设置步骤

下一篇: ServiceStack DELETE请求是默认对象,POST工作正常