locked
Service operations using POST RRS feed

  • Question

  • I have this service operation defined :

    [WebGet]
    public IQueryable<Order> GetOrdersByCity(string city)
    {
        var context = new WarmCrocEntities();
    
        return context.Orders.Where(o => o.ShipCity == city);
    }


    I can execute this by firing off this HTTP GET request:

    GET http://localhost:49653/Northwind.svc/GetOrdersByCity?city='London' HTTP/1.1
    Accept: text/html, application/xhtml+xml, */*
    Accept-Language: en-US
    User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
    Accept-Encoding: gzip, deflate
    Connection: Keep-Alive
    Host: localhost:49653


    I made another service operation like this

    [WebInvoke(Method = "POST")]
    public IQueryable<Order> GetPostOrdersByCity(string city)
    {
        var context = new WarmCrocEntities();
    
        return context.Orders.Where(o => o.ShipCity == city);
    }

    And thought that I could fire this off by using

    POST http://localhost:49653/Northwind.svc/GetPostOrdersByCity HTTP/1.1
    Accept: text/html, application/xhtml+xml, */*
    Accept-Language: en-US
    User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
    Accept-Encoding: gzip, deflate
    Connection: Keep-Alive
    Host: localhost:49653
    
    city=London

    But when the key/value-pair reaches my WCF Data Service, City has the value of null.

    Looking at my code I simply cannot understand why this is.

    Can any of you guys explain this to me?

    Thanks,


    /Jesper www.idippedut.dk

    Wednesday, January 16, 2013 9:25 PM

Answers

  • I believe that you still want to put the parameter to the service operation in the query string, even though it is a POST.

    Actions take parameters from the body, but service operations get them from the query string.

    -Ian

    Thursday, January 17, 2013 10:44 PM

All replies

  • I believe that you still want to put the parameter to the service operation in the query string, even though it is a POST.

    Actions take parameters from the body, but service operations get them from the query string.

    -Ian

    Thursday, January 17, 2013 10:44 PM
  • I believe that you still want to put the parameter to the service operation in the query string, even though it is a POST.

    Actions take parameters from the body, but service operations get them from the query string.

    -Ian

    Hi Ian,

    thank you - I'll try that out as soon as I get a change to do so.

    But ... the behavior you describe is a bit odd and slightly against the usual convention on how data is sent to the server using HTTP POST vs GET, isn't it?

    :o)


    /Jesper www.idippedut.dk

    Friday, January 18, 2013 12:17 PM
  • Yes, POST-based service operations are odd. Its one of the reasons that 'Actions' was introduced in V3 of the OData protocol. You will have to upgrade to the 5.0 release of WCF Data Services to get this support (if you haven't already). Alex James has posted a series of useful blog posts about Actions on the main team blog. The introductory post is here: http://blogs.msdn.com/b/astoriateam/archive/2011/10/17/actions-in-wcf-data-services.aspx.

    Service operations, whether GET or POST, take all parameters through the query string. The ability to use POST was mainly to be able to make side-effects more obvious. They're functionally equivalent other than the method.


    Matt Meehan (WCF Data Services / OData)

    Thursday, January 24, 2013 10:58 PM
    Moderator