c# - Does the Content-Type of a POST or PUT request need to be 'application/x-www-form-urlencoded' in a WCF ReSTful service? -
what trying is, seemingly, simple: send pox via request body, have wcf service process it, , return 201 status code. in servicecontract have defined following method:
    [webinvoke(method = "put", uritemplate = "/content/add", bodystyle = webmessagebodystyle.bare, responseformat = webmessageformat.xml, requestformat=webmessageformat.xml)]     [operationcontract]     stream addcontent(stream input);   the verb here doesn't matter; replace 'put' 'post' , wind same result. implementation of above method follows:
    public stream addcontent(stream input)     {         weboperationcontext.current.outgoingresponse.statuscode = system.net.httpstatuscode.created;     }   since method of little consequence have omitted of procedural code. test functionality fired fiddler , issued following request:
 user-agent: fiddler  host: myhost.com  content-length: 771  content-type: text/xml && application/xml; charset: utf8  <xmldatagoeshere></xmldatagoeshere>   the supplied value content-type incorrect, know, using illustrate content-type's have tried. if click on 'execute' in fiddler response code service 400 bad request. worth noting service method not getting hit in secnario, request dies before gets there. after copious amounts of reading , process of elimination changed content-type :
 content-type: application/x-www-form-urlencoded   if execute fiddler request status code returned service 201 created. there missing why can't set content-type urlencoded? have tried tweaking bodystyle , requestformat properties in servicecontract did not have impact on outcome. can shed light on why happening?
i think problem related fact when send xml webhttpbinding, detects sending xml , tries deserialize it. ignores fact signature expecting stream. there workarounds have seen can't find links @ moment. if find them i'll update post.
Comments
Post a Comment