wcf - String In XML body with no header -


i have wcf service several methods. log raw request came in client regardless of how sent. using below method

public message createmessage(message message)      {        messagebuffer buffer = message.createbufferedcopy(int32.maxvalue);        var messagecopy = buffer.createmessage();        console.writeline(messagecopy.tostring());        return buffer.createmessage();           }  public object afterreceiverequest(ref system.servicemodel.channels.message request, system.servicemodel.iclientchannel channel, system.servicemodel.instancecontext instancecontext)         {             request = createmessage(request);             return null;          } 

i xml in result , string in body headers want string in body no header @ all. can me in regard.

finally sort out , solution overwrite body writer class. please find detailed solution below.

namespace wcfserviceraw {     // note: can use "rename" command on "refactor" menu change interface name "iservice1" in both code , config file together.     [servicecontract]     public interface iservice1     {          [operationcontract(replyaction = "responsetogetdatarequest")]         message getdata();     }  } namespace wcfserviceraw {     // note: can use "rename" command on "refactor" menu change class name "service1" in code, svc , config file together.     public class service1 : iservice1     {          public message getdata()         {             // create body             testdatawriter body = new testdatawriter("<test>data</test>");              // create messatge             messageversion ver = operationcontext.current.incomingmessageversion;             message msg = message.createmessage(ver, "responsetogetdatarequest", body);              //debug.writeline(msg.tostring());             return msg;          }      }      class testdatawriter : bodywriter     {         string _data;          public testdatawriter(string data)             : base(false)         {             _data = data;         }          protected override void onwritebodycontents(xmldictionarywriter writer)         {             writer.writeraw(_data);         }     } 

and client is:

namespace wcfclientraw {     class program     {         static void main(string[] args)         {             //imycontract proxy = channelfactory<imycontract>.createchannel(new basichttpbinding(), new endpointaddress(address));             wcfserviceraw.service1client proxy = new wcfserviceraw.service1client();             using (proxy idisposable)             {                 message msg = proxy.getdata();                 console.writeline(msg.tostring());                 console.writeline();                  xmldictionaryreader xdr = msg.getreaderatbodycontents();                 //string exp = "<test>data</test>";                 string act = xdr.readouterxml();                 //debug.assert(exp == act);                 console.writeline(act);                 console.readline();             }         }     } } 

Comments

Popular posts from this blog

java - JavaFX 2 slider labelFormatter not being used -

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -