c# - WCF and RESTful API: remote server returned bad request 400 on DELETE method -
i checked ton of posts/tutorials/videos still can't working code delete method in 1 specific case: when i'm trying delete id.
working sample below. i'm passing whole json string delete method , works (based on dare suggest there no errors in wcf/client configuration files).
wcf
[operationcontract] [webinvoke(method = "delete", responseformat = webmessageformat.json, requestformat = webmessageformat.json, uritemplate = "delete" )] bool deletenews(news news);
client:
const string webservice_url = "http://localhost:33873/newsservice.svc/delete"; string jsondata = "{my json string}"; try { var webrequest = webrequest.create(webservice_url); if (webrequest != null) { webrequest.method = "delete"; webrequest.timeout = 20000; webrequest.contenttype = "application/json"; using (stream s = webrequest.getrequeststream()) { using (streamwriter sw = new streamwriter(s)) sw.write(jsondata); } using (stream s = webrequest.getresponse().getresponsestream()) { } } }
now demonstrate following code doesn't work me. i'm wondering can't use delete id.
wcf
[operationcontract] [webinvoke(method = "delete", uritemplate = "delete/?id={id}" )] bool deletenews(int id);
putting url browser http://localhost:33873/newsservice.svc/delete/?id=10 , getting "remote server returned bad request code 400" (meaning wrong on client side or request). have tried via string parameter below:
[operationcontract] [webinvoke(method = "delete", uritemplate = "delete/{id}" )] bool deletenews(string id);
after such transformation, url looks http://localhost:33873/newsservice.svc/delete/10
result unsuccessfull same error.
have enabled "delete" verb in iisexpress
http://www.iis.net/learn/extensions/introduction-to-iis-express/iis-express-faq http://stevemichelotti.com/resolve-404-in-iis-express-for-put-and-delete-verbs/
you can manually test put,delet verbs fiddler
Comments
Post a Comment