3

I'm trying a put operation against a WCF webapi service using jQuery 1.7.1. The relevant client code is:

$.ajax(
    {
        type: 'PUT',
        contentType: 'application/json',
        dataType: 'json',
        url: '../webapi/esfuerzos/' + id,
        data: { json: args },
        success: function (respuesta) {
            $("cancelarEsfuerzoTerreno").trigger("tap");
        },
        error: function (respuesta) {
            debugger;
        }
    });

The following method signature is on the server:

[WebInvoke(UriTemplate = "{idTicket}", Method = "PUT", RequestFormat = WebMessageFormat.Json)]
public HttpResponseMessage Agregar(int idTicket, JsonValue json)

When I call the client code I get a 500 - internal server error response. What might be causing this?

edit: here's the raw http mesage

PUT http://localhost/mosaq/sae/webapi/esfuerzos/12 HTTP/1.1
Accept: application/json, text/javascript, */*; q=0.01
Content-Type: application/json
X-Requested-With: XMLHttpRequest
Referer: http://localhost/mosaq/sae/movil/
Accept-Language: en-us
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
Host: localhost
Content-Length: 355
Connection: Keep-Alive
Pragma: no-cache
Cookie: ASP.NET_SessionId=jy0shfatrj4icobvagysrnm2

json%5BpreparacionCoordinacionMinutos%5D=null&json%5BpreparacionCoordinacionHoras%5D=null&json%5BesperaMinutos%5D=null&json%5BesperaHoras%5D=null&json%5BtrasladoIdaFin%5D=null&json%5BtrasladoIdaInicio%5D=null&json%5BtrasladoRegresoFin%5D=null&json%5BtrasladoRegresoInicio%5D=null&json%5BejecucionFin%5D=null&json%5BejecucionInicio%5D=null&json%5Btipo%5D=0
Nicolas Straub
  • 3,381
  • 6
  • 21
  • 42
  • You should post the exception associated with the 500 error. That should tell us what the problem is. – Jacob Dec 02 '11 at 20:25
  • how can I get the exception? I put a breakpoint in the method but it doesn't break :S – Nicolas Straub Dec 02 '11 at 20:27
  • Maybe there's something in the Windows application log. – Jacob Dec 02 '11 at 20:28
  • nope, nothing, already checked =( – Nicolas Straub Dec 02 '11 at 20:30
  • the iis log says this: ::1, -, 12/2/2011, 17:26:57, W3SVC1, NICO-VHD, ::1, 217, 840, 1887, 500, 0, PUT, /mosaq/sae/webapi/esfuerzos/12, -, – Nicolas Straub Dec 02 '11 at 20:31
  • In your web.config, you can configure your error handling to provide you with more details. You should post that anyway in case we can spot a configuration issue. – Jacob Dec 02 '11 at 20:33
  • I'm unfamiliar with the syntax for web.config. could you tell me how to enable this? – Nicolas Straub Dec 02 '11 at 20:56
  • See http://msdn.microsoft.com/en-us/library/ff649234.aspx – Jacob Dec 02 '11 at 21:02
  • The problem I have with this is that I don't have behaviours configured, since with webapi routes are added in the appstart section in global.asax. can I still create a new behavior and link it to my service or should I configure something in global.asax? – Nicolas Straub Dec 02 '11 at 21:17
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/5537/discussion-between-nicolas-straub-valdivieso-and-jacob) – Nicolas Straub Dec 02 '11 at 21:20
  • the problem was that the data object wasn't getting serialized properly. calling json.stringify on the args object solved the issue. – Nicolas Straub Dec 02 '11 at 21:50

3 Answers3

1

If you see server side errors and a breakpoint on the fist like of you service method is never reached the best thing is to enable tracing and use the Service Trace Viewer Tool to view the output. There might be a lot of output but focus on errors (red) and warnings (in yellow).

See this the answer to this question and the MSDN docs here how to configure things.

Community
  • 1
  • 1
Maurice
  • 27,582
  • 5
  • 49
  • 62
0

Most probably the client sets wrong request type. For example, should be "text/xml" but is "appliation/x-www-form-urlencoded".

Wiktor Zychla
  • 47,367
  • 6
  • 74
  • 106
0

the problem was that the data object wasn't getting serialized properly. calling json.stringify on the args object solved the issue.

thanks to jason for helping me figure it out!

Nicolas Straub
  • 3,381
  • 6
  • 21
  • 42