2017-05-25 11 views
1

私はピッキングプロセスを使用する会社にWebappを開発しています。Web Api Http Putを使用した場合の内部サーバーエラー500

このプロセスは非常に単純です。私はいくつかの情報を含む受注を持っており、その情報のいくつかを持つピッキングリストを作成しています(たとえば、アイテム数、合計重量、受注ID)。

私はピッキングリストを作成し、データベースにそれを追加するために、PUTメソッドを使用しようとしているとき、私は...いつもこのエラーを取得

内部サーバーエラー

よWeb Api側で

私は[HttpPost]削除にエラー変更:

または

この

を許可されていません

メソッドが見つかりません

方法は、私のコードは次のとおりです。

クライアント側

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; 
} 

Web APIをサイド - コントローラ私はこの種の問題に関連するいくつかの解決方法を試し

//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 StatusCode(HttpStatusCode.Created); 
} 

、同じエラー(複数可)。

ファイル\のMicrosoft Visual メーカー:私は私の解決策を再構築すると

のWeb.config

<?xml version="1.0" encoding="utf-8"?> 
<!-- 
    For more information on how to configure your ASP.NET application, please visit 
    https://go.microsoft.com/fwlink/?LinkId=301879 
    --> 
<configuration> 
    <configSections> 
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> 
     <section name="PrimaveraRest.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
    </sectionGroup> 
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> 
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
    </configSections> 
    <appSettings> 
    <add key="webpages:Version" value="3.0.0.0" /> 
    <add key="webpages:Enabled" value="false" /> 
    <add key="ClientValidationEnabled" value="true" /> 
    <add key="UnobtrusiveJavaScriptEnabled" value="true" /> 
    </appSettings> 
    <system.web> 
    <compilation debug="true" targetFramework="4.5.2" /> 
    <httpRuntime targetFramework="4.5.2" /> 
    <httpModules> 
     <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" /> 
    </httpModules> 
    </system.web> 
    <system.webServer> 
    <handlers> 
     <remove name="ExtensionlessUrlHandler-Integrated-4.0" /> 
     <remove name="OPTIONSVerbHandler" /> 
     <remove name="TRACEVerbHandler" /> 
    <!-- <remove name="WebDAV"/> --> 

     <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /> 
    </handlers> 
    <validation validateIntegratedModeConfiguration="false" /> 
    <modules> 

    <!-- <remove name="WebDAVModule"/> --> 
     <remove name="ApplicationInsightsWebTracking" /> 
     <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" /> 
    </modules> 


    </system.webServer> 
    <runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly> 
     <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" /> 
     <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" /> 
     </dependentAssembly> 
    </assemblyBinding> 
    </runtime> 
    <system.codedom> 
    <compilers> 
     <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" /> 
     <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" /> 
    </compilers> 
    </system.codedom> 
    <applicationSettings> 
    <PrimaveraRest.Properties.Settings> 
     <setting name="Company" serializeAs="String"> 
     <value>DEMO</value> 
     </setting> 
     <setting name="User" serializeAs="String"> 
     <value>adminfixe</value> 
     </setting> 
     <setting name="Password" serializeAs="String"> 
     <value>123456</value> 
     </setting> 
    </PrimaveraRest.Properties.Settings> 
    </applicationSettings> 
    <entityFramework> 
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"> 
     <parameters> 
     <parameter value="mssqllocaldb" /> 
     </parameters> 
    </defaultConnectionFactory> 
    <providers> 
     <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> 
    </providers> 
    </entityFramework> 
</configuration> 

UPDATE

、私はこのようないくつかの行を取得しています\ 2017 \コミュニティ\ MSBuild \ 15.0 \ Bin \ Microsoft.Common.CurrentVersion.targets(19645): warning MSB3270:プロジェクト "MSIL"とプロセッサ アーキテクチャ "Interop.ICrmDS800"、 "x86"のプロセッサ アーキテクチャの間に不一致がありました。この が一致しないと、実行時にエラーが発生する可能性があります。 プロジェクトのターゲットプロセッサアーキテクチャを 構成マネージャで変更して、プロセッサアーキテクチャ をプロジェクトと参照の間に配置するか、ターゲットの プロセッサアーキテクチャに一致するプロセッサアーキテクチャの 参照に依存するようにしてくださいプロジェクト

問題がありますか? Interop。dllは私のプロジェクトで、外部プログラムを使用して受注に関する情報を取得するファイルです。

SOLUTION

[キー]注釈は「ListaPicking」モデルに欠けている、と私はデフォルト値で日付と時刻の変数を渡していた...私はちょうど例えばDateTime.Todayに変更し、今では働いています:)

+1

結果を確認してください。メンバーにアクセスする前に長さを確認してください。また、コードをデバッグし、サーバー側の例外を質問に追加する方が良いでしょう。 –

答えて

1

は、あなただけの代わりに解体し、それを再構築するのと同じように、モデル全体

public async Task<bool> AddTarefa(ListasPicking listaPickingAdd) { 

    var response = await cliente.PutAsJsonAsync("api/ListasPicking/", listaPickingAdd); 

    return response.IsSuccessStatusCode;   
} 

を送信し、行動でそれを受け取ることができます。

[ResponseType(typeof (ListasPicking))] 
[HttpPut] 
public IHttpActionResult PutLista ([FromBody] ListasPicking novaLista) { 
    if(!ModelState.IsValid) { 
     return BadRequest(ModelState); 
    } 

    primContext.ListasPickingGet.Add(novaLista); 
    primContext.SaveChanges(); 

    return StatusCode(HttpStatusCode.Created); 
} 
+0

私はまだエラーが発生しています...私の更新を見てください! – bullprog

+0

@bullprogエラーメッセージ – Nkosi

+0

@bullprogチェックアウトhttps://stackoverflow.com/a/10196549/5233410 – Nkosi

2

あなたはPutAsJsonAsyncを呼び出しますが、jsonを表す文字列が必要な場合は、データパラメータとして非json文字列を渡します。ドキュメントから

はJSONとしてシリアライズ所定の値で指定されたURIに対する非同期動作としてPUT要求を送信します。

代わりにPutAsyncに電話をかけてください。

+0

は、文字列をhttp.contentに変換できないことを通知します。 – bullprog

+0

@bullprog - ヘッダーに 'content-type'を設定し、' application/x-www-form-urlencoded'を使い、文字列の値の前に '='をつけてください。 [documentation](https://msdn.microsoft.com/en-us/library/hh138124(v = 118).aspx)を参照してください。 – Igor

関連する問題