0
I am developing a picking software, where the user from a sales order (order) creates a picking list (which contain the products that the warehouse employee will pick up for later transport to take the person’s home).
Whenever I try to create a new picking list the answer always comes false.
My code is this::
Client side - creating and sending to the Information Webapi
public async Task<bool> AddTarefa(ListasPicking listaPickingAdd)
{
String listaparaAdicionar = listaPickingAdd.idLista + ";" + listaPickingAdd.IDordemVenda + ";" + listaPickingAdd.peso + ";" + listaPickingAdd.itens;
HttpResponseMessage response = await cliente.PutAsJsonAsync("api/ListasPicking/", listaparaAdicionar);
return response.IsSuccessStatusCode; // esta resposta vem sempre false.
This variable response
always came with the value false and with one of these mistakes.
Method Not Allowed
Method Not Found
After having changed a few lines of code gives this:
Internal Server Error
Webapi side
private PrimaveraRestContext primContext = new PrimaveraRestContext();
//PUT: api/ListasPicking
[ResponseType(typeof (ListasPicking))]
[HttpPut]
public IHttpActionResult PutLista ([FromBody] String lista)
{
if(!ModelState.IsValid)
{
return BadRequest(ModelState);
}
String[] result = lista.Split(';');
ListasPicking novaLista = new ListasPicking();
novaLista.idLista=result[0];
novaLista.IDordemVenda = result[1];
string lista_peso_converttoDouble = result[2];
novaLista.peso = Convert.ToDouble(lista_peso_converttoDouble);
string lista_items_converttoInt = result[3];
novaLista.itens = Convert.ToInt32(lista_items_converttoInt);
primContext.ListasPickingGet.Add(novaLista);
primContext.SaveChanges();
return null;
}
Web.Config
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
</configSections>
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Optimization"/>
<add namespace="System.Web.Routing" />
<add namespace="PrimaveraRest" />
</namespaces>
</pages>
</system.web.webPages.razor>
<appSettings>
<add key="webpages:Enabled" value="false" />
</appSettings>
<system.webServer>
<handlers>
<remove name="BlockViewHandler"/>
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
</system.webServer>
<system.web>
<compilation>
<assemblies>
<add assembly="System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
</system.web>
</configuration>
Ever tried using public
public async Task IHttpActionResult PutLista([FromBody] String lista)
?– L. Jhon
tells me async is not compatible with Httpactionresult.
– ZelDias