Note that there are some explanatory texts on larger screens.

plurals
  1. POhttp post on a WCF web api service using restsharp
    primarykey
    data
    text
    <p>Im trying to post some information in my api which is programmed using WCF Web Api. In the client, I'm using restsharp which is a rest client for restful services. However, when I try to post adding some parameters to the request, the post method in the service is never called, and my response object in the client gets a 500 status (internal server error), but when I comment the lines where I'm adding parameters the request reaches the post method exposed in the service.</p> <p>Here's the code from the client:</p> <pre><code>[HttpPost] public ActionResult Create(Game game) { if (ModelState.IsValid) { var request = new RestRequest(Method.POST); var restClient = new RestClient(); restClient.BaseUrl = "http://localhost:4778"; request.Resource = "games"; //request.AddParameter("Name", game.Name,ParameterType.GetOrPost); this is te line when commented everything works fine RestResponse&lt;Game&gt; g = restClient.Execute&lt;Game&gt;(request); return RedirectToAction("Details", new {id=g.Data.Id }); } return View(game); } </code></pre> <p>Here's the code for the service:</p> <pre><code>[WebInvoke(UriTemplate = "", Method = "POST")] public HttpResponseMessage&lt;Game&gt; Post(Game game, HttpRequestMessage&lt;Game&gt; request) { if (null == game) { return new HttpResponseMessage&lt;Game&gt;(HttpStatusCode.BadRequest); } var db = new XBoxGames(); game = db.Games.Add(game); db.SaveChanges(); HttpResponseMessage&lt;Game&gt; response = new HttpResponseMessage&lt;Game&gt;(game); response.StatusCode = HttpStatusCode.Created; var uriBuilder = new UriBuilder(request.RequestUri); uriBuilder.Path = string.Format("games/{0}", game.Id); response.Headers.Location = uriBuilder.Uri; return response; } </code></pre> <p>I need to add parameters to my request so the game object in the service gets populated, but I dont know how to do this, if the service breaks every time I try to add parameters.</p> <p>I forgot to mention that both client and server are .NET MVC 3 applications. </p> <p>Any help would be appreciate it. Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload