0
我想創建一個Web應用程序,它使用ReSTful結構接受單個POST方法來更新數據庫。來自ReST POST請求方法的錯誤404
我的問題是,當我發佈一個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 }
感謝
你的基址的配置和您運行的localhost端口看起來不同。使用正確的基地址,然後嘗試 – Sachin 2013-05-06 09:31:52
您的基地址與fiddler請求不同,並且項目正在運行還是託管在Iis中? – christiandev 2013-05-06 09:36:19
我在iis測試。我已將基址更改爲:http:// localhost/vi /和UriTemplate =「vi/projectorors」界面中的URI合約 - 仍然表示錯誤404(我已發佈對iis的新更改) – beaumondo 2013-05-06 09:42:43