.NET 4.0でWCF RESTサービスを設定しています。 GET要求は機能していますが、サーバーへのデータのPOSTを含む要求は、HTTP 400 Bad Request
で失敗します。WCF REST 4.0 PUT/POST/DELETEが機能しない(400 Bad Request)
この私の単純なサービスされています
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
public class Service1
{
[WebGet(UriTemplate = "")]
public string HelloWorld()
{
return "hello world";
}
[WebInvoke(UriTemplate = "", Method = "POST")]
public string HelloWorldPost(string name)
{
return "hello " + name;
}
}
私のWeb.config:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</modules>
</system.webServer>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<protocolMapping>
<add scheme="http" binding="webHttpBinding" />
</protocolMapping>
<standardEndpoints>
<webHttpEndpoint>
<!--
Configure the WCF REST service base address via the global.asax.cs file and the default endpoint
via the attributes on the <standardEndpoint> element below
-->
<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"/>
</webHttpEndpoint>
</standardEndpoints>
</system.serviceModel>
</configuration>
そして、私のGlobal.asax:
public class Global : HttpApplication
{
void Application_Start(object sender, EventArgs e)
{
RegisterRoutes();
}
private void RegisterRoutes()
{
RouteTable.Routes.Add(new ServiceRoute("Service1", new WebServiceHostFactory(), typeof(Service1)));
}
}
基本的に、すべてがテンプレートからデフォルトですただ、Service1
を簡略化しました。私はデバッガを使って実行し、Fiddlerを介してリクエストを渡してIISで実行し、同じことをやっているだけでなく、POSTをフェイクするためのシンプルなコンソールアプリケーションを使ってみましたが、いつも400 Bad Request
エラーが発生し、 。私はインターネット上のすべてを見て、何かを把握することはできません。
私は、次の要求の例(いずれも作業)の両方を試してみた:
XML:
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">String content</string>
JSON:
"String content"
なぜ残りのタグが削除されたのですか?この投稿はREST Webサービスに関するものです。 – shuniar
この投稿はHTTP、WCF、ASP、.NETなどについての質問です。 RESTアーキテクチャ実装上の問題であり、設計やアーキテクチャの問題ではありません。 –
GET版のHelloWorldは機能しますか? –