c# - How to write the response to the text file -


I am trying to log request response from service to a text file. I'm using log4net to log the answer to a text file, but it is only logging the request but the response is not there. How can I do this?

  public void AfterReceiveReply (reference System.ServiceModel.Channels.Message reply, objected correlationState) {if (log.IsErrorEnabled) {SaveResponseToLog ( "AfterReceiveReply" + "\ n ##### VisService Soap Response ##### \ n "); String file name = environment Getfolderpath (environment. Viseshfolder. Application Data) + "\\ Daimler AG \\ vis @ \" "+" log.txt "; System.Xml.XmlDictionaryWriter writer = null; Sndeshbfr buffer = North. Kretbufrdkapi (Int32kMaxValue); Answer = Buffer. Crete Message (); System.ServiceModel.Channels.Message AnswerCopy = Buffer .Tet Message (); {FileStream FS: Try New FileStream (File Name, FileMod. Append, FileAccess.Write); Author = System .xml.xmlDictionaryWriter.CreateTextWriter (fs); replyCopy.WriteMessage (Author); MessageBox.Show ("AfterReceiveReply" + Author.ToString ()); writer.Flush ( );} Hold (Exception e) {// Something went wrong when writing in the feedback message box. Show (E. Message);} Finally {author. Close ();}} Public Object BeforeSendRequest (Reference System.ServiceModel.Channels .message request, IClientChannel channel) {if (log.IsErrorEnabled) {string visServiceSOAPRequest = request.ToString (); log error ("error: VisService SOAP request>>>); log.Error ( VisServiceSOAPRequest); // mail Confirmation box to display messages in SaveResponseToLog ("BeforeSendRequest" + "\ nVisService Soap Request & gt; & Gt; & Gt; \ N "+ visServiceSOAPRequest);} return null;} private void SaveResponseToLog (String message) {System.IO.StreamWriter writer = null; // StreamReader rd = null; String filename = environment. Getfolderpath (environment. Viseshfolder. Application Data ) + "\\ My app \\ application \\" + "log.txt"; if (! File .example (file name)) {(filestream fs = new filestream (file name, filemod.openoffrat, file accessedReadright) }) {Fs.Flush (); fs.Close ();}} Try {if (File.Exists (filename)) {writer = System.IO.File.AppendText (filenam) E); writer.Write (message); writer.flush ();}} grip (exception e) {// wenn das loggen nicht funktioniert, kann der fehler ja nicht geloggt werden .. log.Error ("error log.txt Saving the message in the file: "+ e.Message);} Finally {the author} closed ();}}    

The following codes only work for me [MyServiceBehavior]

The request can be seen in the AfterReceiveRequest method.

The answer can be seen in the BeforeSendReply method is.

  public while decorating your service implementation class MyServiceBehaviorAttribute: characteristic, IServiceBehavior {public void AddBindingParameters (ServiceDescription serviceDescription, ServiceHostBase Sewahostbej, collection & lt; Sewaindpoint & gt; endpoint, binding Prmeteyrclekshn binding Prmetrs ) {} Make Public Zero ApplicationSearch Specialist (Service Description Description Service, Service HostBase Service Hostbase) {foreach (ServiceDespatcher chDisp in serviceHostBase.ChannelDispatchers) {foreach (Endpoint Disks) Pastor at APDISP chDisp.Endpoints) {epDisp.DispatchRuntime.MessageInspectors.Add (new Inspector ()); Forechap (Dispatch Operation Op in APIDSP. Dispatant. Operation) Op. Parameter Inspector Add (new inspector ()); }}} Public void validate (Service Revision service description, Sewahostbes Sewahostbej) {}} public class Inspector: IDispatchMessageInspector, after IParameterInspector {public object RéceiveRequest (reference message request, IClientChannel channel, InstanceContext instanceContext) {Console.WriteLine ( "IDispatchMessageInspector. AfterReceiveRequest. "); Return tap; } Send reply before public zero (reply to ref message, object correlation: stat) {console. Videoline (called "IDispatchMessageInspector.BeforeSendReply."); } [Public void AfterCall (string operationName, object] Output ReturnValue objection, objection correlationState) {Console.WriteLine ( "IParameterInspector.AfterCall called to {0} with the return value {1}.", OperationName, returnValue. ToString ()); } Call before public object (string operation name, object [] input) {Console.WriteLine (called "IParameterInspector.BeforeCall {0}.", OperationName); Return tap; }}    

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -