Question

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.

Was it helpful?

Solution 2

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.

OTHER TIPS

Try setting the bodystyle as below.

 [WebInvoke(Method = "PUT", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top