我想创建一个 Web 应用程序,它接受一个 POST 方法来更新数据库,使用 ReSTful 结构。
我的问题是,当我将 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 }
谢谢