c# - Recreating a Message in WCF -
i retrieving data server via wcf (i client). unfortunately, server (which have no control of) returning invalid xml.
in order fix this, plan add iclientmessageinspector
(on client), modifies message
before wcf has chance parse returned xml.
my first step implement iclientmessageinspector
, have leaves response unchanged (it should no-op), reason causes generated wcf method (client.getbar()
below) return null
object, rather populated object.
class utf8policer : iclientmessageinspector { public void afterreceivereply(ref message reply, object correlationstate) { message revised = null; var contents = new stringbuilder(); var writer = xmlwriter.create(contents); reply.writemessage(writer); writer.flush(); revised = message.createmessage(reply.version, reply.headers.action, xmlreader.create(new stringreader(contents.tostring())); revised.headers.copyheadersfrom(reply); revised.properties.copyproperties(reply.properties); reply = revised; } public object beforesendrequest(ref message request, iclientchannel channel) { return null; } }
however, when running:
var client = new foo_rpcclient(); var header = new header(); // registers inspector client.endpoint.endpointbehaviors.add(new fooendpointbehaviour()); var response = client.getbar(ref header, new barrequest());
... response
null. if comment out inspector registration, response
works.
my conclusion therefore i'm somehow invalidating message within afterreceivereply
. can advise correct way re-create message received?
once i've got working, i'm hoping it'll trivial fixup xml within afterreceivereply
, useful.
ref parameter wont work wcf.
when call service pass input message serialized. service deserialize , work , return serialized response client deserialized on client side.
the ref parameter might compile in no way retain reference memory pointer in client computer. must use response return object.
Comments
Post a Comment