beaumondo
beaumondo

Reputation: 4930

Error 404 from ReST POST request method

I would like to create a web application that accepts a single POST method to update a db, using a ReSTful structure.

My problem is that when I post a JSON object to the URL (using fiddler) I receive an error 404.

The method I am trying to call is exposed using the attributes below:

[WebInvoke(Method="POST", UriTemplate="projectors", RequestFormat=WebMessageFormat.Json,BodyStyle=WebMessageBodyStyle.Wrapped )]
[OperationContract]
void RecordBreakdown(string sn, int modelCode); 

The web config file has a service that binds to the exposed method, below is an abstraction:

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

If I run the web app in VS or by IIS I can see the svc file okay:

http://localhost:5970/Service.svc
http://localhost/vi/Service.svc

But when I post a request I receive an error 404 message

POST http://localhost/vi/projectors HTTP/1.1
User-Agent: Fiddler
Host: localhost
Content-Length: 27

{sn:"23434", modelCode:34 }

Thanks

Upvotes: 0

Views: 5203

Answers (1)

beaumondo
beaumondo

Reputation: 4930

The error 404 was happening for two reasons.

1st: The base address was incorrect. I was using a naming convention from an earlier version which had been superceeded

2nd: The url in the POST method was incorrect. I should have included the name of the Service file in the url, like localhost/vi/Service.svc/projectors

I also found the folloiwng article helpful http://msdn.microsoft.com/en-us/library/dd203052.aspx to solve the problem

Upvotes: 1

Related Questions