Private static void createerrorreply (operationcontext operationcontext, string key, httpstatuscode statuscode, responsebase info=null, string description = null) { using ( Message reply = message.createmessage (messageversion.none, "", info, new DataContractJsonSerializer (typeof (Responsebase))) { Var wbfprop = new system.servicemodel.channels.webbodyformatmessageproperty ( Webcontentformat.json); // Constructing HTTP Response message Httpresponsemessageproperty responseprop = new httpresponsemessageproperty () { statuscode = statusCode, statusdescription = description ?? "", SuppressEntityBody=false, }; reply. Properties.add (httpresponSemessageproperty.name, responseprop); reply. Properties.add (Webbodyformatmessageproperty.name, wbfprop); OperationContext.RequestContext.Reply (Reply); // because the configuration uses transfermode= "Streamedrequest", if the request does not close, will also enter this class, resulting in this method is executed two times, can not return the normal error code OperationContext.RequestContext.Close (); operationContext.RequestContext = null; } }
WCF service returns JSON