Put Request is not working?

Topics: Web Api
Nov 15, 2011 at 8:36 PM
Edited Nov 15, 2011 at 9:05 PM

Here is my server code:

    <WebInvoke(UriTemplate:="WebMaint", Method:="Put")>
    Public Function WebMaintPut(ByVal entries As IList(Of WebMaint)) As HttpResponseMessage(Of WebMaint)
        Dim response As New HttpResponseMessage(Of WebMaint)(HttpStatusCode.NoContent)
        Using scope = New TransactionScope()
            entries.AsParallel().ForAll(Sub(entry)
                                            _repos.Update(entry)
                                        End Sub)
            scope.Complete()
        End Using

        Return response
    End Function

My Client Code: 
        Using client = New HttpClient()

            Dim Content = New ObjectContent(Of IList(Of WebMaint))(_WebMaint)
            Dim response = client.Put(New Uri("http://localhost:8000/REST/WebMaint/"), Content)

          
        End Using
From the client side everything seems to be working correctly. 
It flies right by the "Client.Put" call but the server code is actually never called (i never hit my breakpoint).
 My GET calls are working perfectly. I even tried to put an "invalid url" into the "Client.Put". 
 I expected it to fail but it did the same thing.
 
 What am i doing wrong?

Update: I tried submitting the put request through fiddler and i'm still getting a 404 error
Nov 15, 2011 at 8:49 PM

Sorry i wasn't looking at the httpstatuscode of the response object before. Its actually reporting a HTTP 404 (NOT FOUND) which makes no sense to me. I know the resource is there. 

Coordinator
Nov 15, 2011 at 8:56 PM

Could you please show us a trace of the client request?

Daniel Roth

Nov 15, 2011 at 9:13 PM
danroth27 wrote:

Could you please show us a trace of the client request?

Daniel Roth

Thanks Daniel for the reply. I sure could if i knew how to do it :P. Can you send me any info on how to provide you this trace?

Nov 15, 2011 at 9:29 PM
ncage1974 wrote:
danroth27 wrote:

Could you please show us a trace of the client request?

Daniel Roth

Thanks Daniel for the reply. I sure could if i knew how to do it :P. Can you send me any info on how to provide you this trace?

I think i figured out how to do it. Just added the following to my app.config:

          <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
            <listeners>
              <add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData="c:\log\traces.svclog" />
            </listeners>            
          </source>

How can i go about uploading the traces.svclog to you?
Coordinator
Nov 15, 2011 at 9:39 PM

I really just need to see the raw HTTP request. The easiest way to do this is probably to use Fiddler.

Daniel Roth

From: ncage1974 [email removed]
Sent: Tuesday, November 15, 2011 1:30 PM
To: Daniel Roth
Subject: Re: Put Request is not working? [wcf:279562]

From: ncage1974

ncage1974 wrote:

danroth27 wrote:

Could you please show us a trace of the client request?

Daniel Roth

Thanks Daniel for the reply. I sure could if i knew how to do it :P. Can you send me any info on how to provide you this trace?

I think i figured out how to do it. Just added the following to my app.config:

          <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
            <listeners>
              <add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData="c:\log\traces.svclog" />
            </listeners>            
          </source>
 
How can i go about uploading the traces.svclog to you?
Nov 16, 2011 at 1:28 PM
Edited Nov 16, 2011 at 1:29 PM

Here you go Daniel.

 

Request:
PUT http://localhost:8000/REST/WebMaint/ HTTP/1.1Host: localhost:8000Content-Length: 592Expect: 100-continue
<?xml version="1.0" encoding="utf-8"?><ArrayOfWebMaint xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><WebMaint><WebMaintenanceID>1</WebMaintenanceID><Maintenance>true</Maintenance><WebSystemId>1</WebSystemId><WebMsgId>4</WebMsgId></WebMaint><WebMaint><WebMaintenanceID>2</WebMaintenanceID><Maintenance>true</Maintenance><WebSystemId>2</WebSystemId><WebMsgId>3</WebMsgId></WebMaint><WebMaint><WebMaintenanceID>3</WebMaintenanceID><Maintenance>true</Maintenance><WebSystemId>3</WebSystemId><WebMsgId>2</WebMsgId></WebMaint></ArrayOfWebMaint>

Response:
 HTTP/1.1 404 Not FoundContent-Length: 1565Content-Type: text/html; charset=utf-8Server: Microsoft-HTTPAPI/2.0Date: Wed, 16 Nov 2011 13:22:31 GMT
<?xml version="1.0" encoding="utf-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">  <head>    <title>Service</title>    <style>BODY { color: #000000; background-color: white; font-family: Verdana; margin-left: 0px; margin-top: 0px; } #content { margin-left: 30px; font-size: .70em; padding-bottom: 2em; } A:link { color: #336699; font-weight: bold; text-decoration: underline; } A:visited { color: #6699cc; font-weight: bold; text-decoration: underline; } A:active { color: #336699; font-weight: bold; text-decoration: underline; } .heading1 { background-color: #003366; border-bottom: #336699 6px solid; color: #ffffff; font-family: Tahoma; font-size: 26px; font-weight: normal;margin: 0em 0em 10px -20px; padding-bottom: 8px; padding-left: 30px;padding-top: 16px;} pre { font-size:small; background-color: #e5e5cc; padding: 5px; font-family: Courier New; margin-top: 0px; border: 1px #f0f0e0 solid; white-space: pre-wrap; white-space: -pre-wrap; word-wrap: break-word; } table { border-collapse: collapse; border-spacing: 0px; font-family: Verdana;} table th { border-right: 2px white solid; border-bottom: 2px white solid; font-weight: bold; background-color: #cecf9c;} table td { border-right: 2px white solid; border-bottom: 2px white solid; background-color: #e5e5cc;}</style>  </head>  <body>    <div id="content">      <p class="heading1">Service</p>      <p>Endpoint not found.</p>    </div>  </body></html>

 

Creation of the self-hosted service:

 

_host = New HttpServiceHost(ObjectFactory.GetInstance(Of WebMaintResource), "http://localhost:8000/REST/")
_host.Open()
Nov 17, 2011 at 2:12 PM

I finally figured out the problem after wresting with this for two days. Apparently you guys made Method parameter case sensitive. Changing it from:

<WebInvoke(UriTemplate:="WebMaint", Method:="Put")>
to
<WebInvoke(UriTemplate:="WebMaint", Method:="PUT")>

fixed the problem.

Shouldn't there be a better way? Shouldn't it be case insensitive or maybe be an enumeration instead?  I know you have to probably support custom verbs but i can see a ton of people hitting this and its kind of hard once you get a 404 error to figure out . 

Coordinator
Nov 17, 2011 at 6:51 PM

I’m glad you figured this out.

Please go ahead and file an issue in the Issue Tracker and we will take a look at making the experience better.

Daniel Roth