c# - WCF service HttpResponseMessage type not able to be consumed -
i have question on webservice method not being able consume, httpresponsemessage type. works fine if other type. need pull data linq , return client, however, data return has backslashes on datatime type data, have find ways return pure json data. referring example: [returning raw json (string) in wcf
below implementation method retrieve data used in wcf.
public httpresponsemessage get(long userid,int maxrownum,int folderid,string shortname=null,datetime reportdatefrom=default(datetime),datetime reportdateto = default(datetime), string reportperiod=null,string filename=null, datetime committimefrom = default(datetime), datetime committimeto = default(datetime),string id=null) { //some methods pull data using linq server //i serialised data, put them list before sending them response object, need return pure json format data. httpresponsemessage response = new httpresponsemessage(); string jsonclient = newtonsoft.json.jsonconvert.serializeobject(query.tolist()); byte[] resultbytes = encoding.utf8.getbytes(jsonclient); response.content = new streamcontent(new memorystream(resultbytes)); response.content.headers.contenttype = new mediatypeheadervalue("text/plain"); return response;
in interface - operation contract class. have following:
[operationcontract] [webinvoke(method = "get", responseformat = webmessageformat.json, uritemplate = "?userid={userid}&maxrownum={maxrownum}&folderid={folderid}&shortname={shortname}&reportdatefrom={reportdatefrom}&reportdateto={reportdateto}&reportperiod={reportperiod}&filename={filename}&committimefrom={committimefrom}&committimeto={committimeto}&id={id}")] httpresponsemessage get(long userid, int maxrownum, int folderid, string shortname = null, datetime reportdatefrom = default(datetime), datetime reportdateto = default(datetime),string reportperiod = null, string filename = null, datetime committimefrom = default(datetime), datetime committimeto = default(datetime), string id = null);
however, cannot understand is: method failed consumed if type httpresponsemessage, result being returned webpage not found. whereas if use other return type such string can consume wcf , result returned. try put breakpoint @ string jsonclient, can see data coming in, there data size on byte[] resultbytes. not sure did goes wrong, maybe problem lies on
response.content = new streamcontent(new memorystream(resultbytes)); response.content.headers.contenttype = new mediatypeheadervalue("text/plain"); ? appreciated. thanks
Comments
Post a Comment