Welcome to the Community Exchange

Welcome to the Community Exchange, a place where community members can exchange questions and answers related to DotNetNuke. If you would like more info about the Community Exchange, please visit this page in our Wiki. 

RESTful API with DotNetNuke Web Services

I'm trying to build a RESTful API with DNN 6.2's web services. REST calls for newly created items to be called with a PUT verb.

I'm using my router to send this to the correct function. This works just fine:

routeManager.MapRoute(
    "Revolution/Engine", "{controller}/{id}",
    new { controller = "TriggerPoints", action = "UpdateTriggerPoint",  },
    new { httpMethod = new HttpMethodConstraint("PUT") },
    new[] { "Engine" });

When my UpdateTriggerPoint is fired, I'm having an issue:

[ValidateInput(false)]
[AcceptVerbs(HttpVerbs.Put)]
public ActionResult UpdateTriggerPoint(Models.TriggerPoint triggerPoint)
{
    if (ModelState.IsValid)
    {
       // save to database here
       // problem: triggerPoint only contains empty values!
    }
 
    return Json(true);
 
}

The data is nowhere to be seen once the function hits. How does one read the contents of a PUT verb with the new web services framework?

asked 8/1/2012
Lucas Jans14
Lucas Jans
edited 8/1/2012
Lucas Jans14
Lucas Jans

2 Answers

I'm am not at all sure why the put data is is not bound properly.  If you can successfully POST the data, the model binding for a put should be the same.  

IIS often needs to be configured to support PUTs.  But if that was the problem I would expect that your action would not be called at all.  The core of DNN will not ever be using PUTs for this reason.  However, if you can configure IIS everywhere your service is deployed then PUTs can work for you.

If you do find you need a custom model binder for some reason, you should register it inside the route mapper.  Routes are re-mapped when new portals are added to a DNN installation, so you should include a test to see if your model binder is already present before registering it to ensure you don't register multiple model binders.


answered 8/1/2012 Scott S 233
Scott S
  • My understanding is that webDAV will interfere with puts in a default 7.5 installation. It is not likely the problem you currently face, but a problem for widespread deployment. - Scott S 8/1/2012

  • I believe IIS 7 and up support PUT by default, but I'm not sure about IIS 6. That being said, using request filters, someone can disable any verb. I can see how you wouldn't want to depend on that.
    http://www.iis.net/ConfigReference/system.webServer/security/requestFiltering/verbs/add

    I'm using Backbone which uses the PUT verb by default. If POST does work, I can create a psuedo verb (like PHP folks have to) by adding the attribute _method = PUT.

    I will test to see if the POST method binds the data to the attribute. If not, it looks like I have two options. A custom model binder (which I'm a bit fuzzy on implementing) or reading the raw stream
    Request.InputStream.Position = 0;
    var triggerPointJSON = new StreamReader(Request.InputStream).ReadToEnd();
    And then serializing it. - Lucas Jans 8/1/2012

REST is a pattern and not a standard so theres no exact answer to this, but based on the RFC http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.6 PUT's should not return data but rather update the http status dependant on the result of the PUT request. However there are a bunch of articles where people hack returning data via etags/updated timestamps etc. so I guess you could do something similar.
answered 8/1/2012 cathal connolly 1210
cathal connolly
  • My trouble isn't returning data but accessing the data that is "PUT." When I access the triggerPoint parameter, it's blank, but in examples I've seen on the web it contains the PUT data. - Lucas Jans 8/1/2012

Your Answer

In order to provide an answer to this question, you must Login

I am flagging this question because...




10 inform moderator flags remaining

I am deleting this question because...




I am flagging this answer because...




10 inform moderator flags remaining

Flagging a Post

You have already flagged this post. Clicking "Remove Flag" below will remove your flag, thus reducing the count by one as well.

I am deleting this answer because...




DotNetNuke Corporation

DotNetNuke (DNN) provides a suite of solutions that make designing, building and managing feature-rich sites and communities fast, easy and cost-effective. The DotNetNuke Platform CMS is the foundation for more than one million websites worldwide. DNN Social, our newest solution, enables businesses to create immersive, interactive communities. Thousands of organizations like True Value Hardware, Bose, Cornell University, Glacier Water, Dannon, Delphi, USAA, NASCAR, Northern Health and the City of Denver have leveraged DNN to deploy highly engaging business- critical websites. Our rapid growth in product sales and deployments resulted in DotNetNuke Corp. being named one of the fastest growing private companies in America by Inc. Magazine in 2011 and 2012.