ReSTful 構造を使用して、単一の POST メソッドを受け入れてデータベースを更新する Web アプリケーションを作成したいと考えています。
私の問題は、(フィドラーを使用して) JSON オブジェクトを URL に投稿すると、エラー 404 が表示されることです。
私が呼び出そうとしているメソッドは、以下の属性を使用して公開されています。
[WebInvoke(Method="POST", UriTemplate="projectors", RequestFormat=WebMessageFormat.Json,BodyStyle=WebMessageBodyStyle.Wrapped )]
[OperationContract]
void RecordBreakdown(string sn, int modelCode);
Web 構成ファイルには、公開されたメソッドにバインドするサービスがあります。以下は抽象化です。
<system.serviceModel>
<bindings/>
<services>
<service name="VIServiceToolServiceLibrary.ProjectorService"
behaviorConfiguration="RESTBehaviour">
<endpoint address=""
binding="webHttpBinding"
contract="VIServiceToolServiceLibrary.IProjectorService"
behaviorConfiguration="RESTEndPointbehaviour" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/projectorservice/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="RESTBehaviour">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="RESTEndPointbehaviour">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
VS または IIS で Web アプリを実行すると、svc ファイルが正常に表示されます。
http://localhost:5970/Service.svc
http://localhost/vi/Service.svc
しかし、リクエストを投稿すると、エラー 404 メッセージが表示されます
POST http://localhost/vi/projectors HTTP/1.1
User-Agent: Fiddler
Host: localhost
Content-Length: 27
{sn:"23434", modelCode:34 }
ありがとう