0

I'm struggling sending a PUT request to WCF in format that it expects. I was thinking I could send it much like a GET with a QueryString, but that just kicked back errors.

    //Put operation
    [OperationContract]
    [WebInvoke(UriTemplate = "?tid={transcriptId}&qId={quizId}&cid={choice}&mid={mbox}&status={status}", Method = "PUT", RequestFormat=WebMessageFormat.Json)]
    vTranscript UpdateTranscript(string transcriptId, string quizId, string choice, string mbox, string status);

I also tried sending as XML and JSON file using CURL, but the values from those files weren't picked up by the service (values were null).

[DataContract]
public class vTranscript
{
    [DataMember]
    public bool validUser;
    [DataMember]
    public bool correctAnswer;
    [DataMember]
    public bool recorded;
  }

I'm assuming that my vTranscript does not have to match the parameters I pass in, though I even tried that.

I'm not sure what I'm doing incorrectly. Any suggestions would be greatly appreciated. Thank you.

Trebor
  • 793
  • 3
  • 11
  • 37

2 Answers2

1

Try setting the bodystyle as below.

 [WebInvoke(Method = "PUT", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
Saranya
  • 1,988
  • 16
  • 20
0

Assuming all your parameters are posted you just need the following: (note that the posted names must match the method parameter names)

//Put operation
[OperationContract]
[WebInvoke(Method = "PUT", RequestFormat=WebMessageFormat.Json)]
vTranscript UpdateTranscript(string transcriptId, string quizId, string choice, string mbox, string status);

UriTemplate is to define parameters that are embedded in the url itself.

Wagner DosAnjos
  • 6,304
  • 1
  • 15
  • 29
  • Thank you for your help. That worked, however now I'm getting "405 Method Not Allowed". This seems to have a lot of possible causes when I google for the error message. I'm running everything from within VS2010 so I doubt if it has to do with the cross domain issue I keep seeing. – Trebor Oct 30 '13 at 17:15
  • The PUT and DELETE verbs are disabled by default. This thread (http://stackoverflow.com/a/10907343/2711582) provides information on how to enable them. A workaround on the client side is to do a POST and add the X-HTTP-Method-Override header to specify the actual verb. – Wagner DosAnjos Oct 30 '13 at 18:05
  • After working on this some more, I was able to solve this. I was wrapping my JSON as a JSON array, and not as a simple JSON string. Thank you for your help. – Trebor Oct 30 '13 at 21:20