api - WCF 4: Passing Empty parameters on a GET request -
i'm creating api use request return search results database, i'm trying make optional parameters can passed (easy wcf) if parameters specfied in query string long empty ignored service.
however if have query string empty parameters return bad request (400) server e.g.
using end-user point of choice pass following querystring
http://www.exampleservice.com/basic/?apikey=1234&noofresults=3&maxsalary=&minsalary=&ouid=0&keywords=web+developer
note maxsalary , minsalary not passing values
you have following wcf service:
[operationcontract] [webget(uritemplate = "basic/?apikey={apikey}&noofresults={noofresults}&maxsalary={maxsalary}&minsalary={minsalary}&ouid={ouid}&keywords={keywords}", bodystyle = webmessagebodystyle.bare)] public list<searchresultsdto> basicsearch(string keywords, string apikey, int noofresults, int maxsalary, int minsalary, int ouid) { //do service stuff }
this cause 400 error, please can explain how pass empty parameters across wcf service or not possible?
currently passing null or empty parameter not supported in wcf, main solution problem override querystringconverter handles url comes through pipe before reaches operation contract.
an excellent example of implmenting extension of querystringconverter found here:
however sadly there bug in wcf 4 cannot override querystringconverter, has been addressed microsoft , fixed in sp1 release coming year.
until there no clean way deal situation other handle exception , return status code of 400 (bad request) - documentation of api should handle in interim.
Comments
Post a Comment