json - request addparameter array but return empty in response -


i use restsharp.

i have list private list<string> _guyids; then

        [testmethod]     public void guymetadataserviceshouldreturnexpected()     {         var client = new restclient("http://localhost/orionservices/guyservice.svc/");          var request = new restrequest("{facilityid}/guys/metadata/", method.post);         request.addurlsegment("facilityid", "888");         request.addparameter("guyids", jsonconvert.serializeobject(_guyids.toarray()), parametertype.requestbody);          var response = client.execute(request);         dynamic data = jsonconvert.deserializeobject<dynamic>(response.content); 

in service,

        [operationcontract]     [webinvoke(method = "post", bodystyle = webmessagebodystyle.wrappedresponse, requestformat = webmessageformat.json, responseformat = webmessageformat.json, uritemplate = "/{facilityid}/guys/metadata/")]     public list<dynamic> generatemetadata(string facilityid)     {         weboperationcontext.current.outgoingresponse.headers.add("cache-control", "no-cache, must-revalidate");         weboperationcontext.current.outgoingresponse.headers.add("expires", "sat, 26 jul 1997 05:00:00 gmt");          var guys = encoding.utf8.getstring(operationcontext.current.requestcontext             .requestmessage.getbody<byte[]>()); 

when hover on guys in service code, got

["0001","0003","0004","0005","0006"]

however when check response, content empty. guess wrong when passed array request in line.

request.addparameter("guyids", jsonconvert.serializeobject(_guyids.toarray()), parametertype.requestbody); 

how fix it?

figure out myself. wcf doesn't support serializing dynamic type. have define poco object.

   [operationcontract] [webinvoke(method = "post", bodystyle = webmessagebodystyle.wrappedresponse, requestformat = webmessageformat.json, responseformat = webmessageformat.json, uritemplate = "/{facilityid}/guys/metadata/")] public list<guysdto> generatemetadata(string facilityid) {     weboperationcontext.current.outgoingresponse.headers.add("cache-control", "no-cache, must-revalidate");     weboperationcontext.current.outgoingresponse.headers.add("expires", "sat, 26 jul 1997 05:00:00 gmt"); 

then

public class guydto {      public string metadata1 {get;set;}       .... } 

Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -