I have a console application that's calling a web service method.
In the web service method, I am using System.Console.WriteLine
, but its getting ignored.
How can I give feedback to the console application from within my web service method?
I have a console application that's calling a web service method.
In the web service method, I am using System.Console.WriteLine
, but its getting ignored.
How can I give feedback to the console application from within my web service method?
You can't because System.Console.WriteLine
will write to the server console, whereas you want output on the client console.
You can use a logging framework like the one in the SixPack library, or Log4Net to write logging messages to a file for example.
In order to be able to write on the client console, you need to put your Console.WriteLine
statements in the client application.
Where your Web Service is hosted? I suppose Web Service is on IIS, so it is a separate process. It can be installed on the same machine or on the different machine, but in any way it will be different process and it cannot write to the console of the client application. It can write to log files, for example, using system.diagnostics.trace or Log4Net open source logging tool
I suggest you to start with this article: ASP.NET Quickstart Tutorials: Monitoring Your Application to understand what choices you have to log and monitor your ASPX web services
An alternative is to have the web service 'tell' the console app what it's doing; to keep a running log.
This is a slightly unusual thing to try and do. If you want to log the activity of the server then I'd use the Trace.WriteLine()
to write to a log file.
However if you want to view server log information on a client then you could get the server to log to a string variable on the web server and then have a GetLog()
web method to retrieve the log information to the client. You can then write it out in the console window. This would require you to call the GetLog()
web method quite frequently but you'll get the result you want. There will probably be a whole host of issues with this, such as requesting a large volume of log information in a single call.
You could also consider using the EventLog support in System.Diagnostics
to create a log of what the web service has done.
When we are testing our web services on our development server we often use the Visual Studio remote debugger to hook up to the webservice code running remotely, and use Debug.WriteLine
calls to keep track of what is happening. Not something that is recommended for a live server, but for development and testing where you often need more detail it is a worthwhile technique.
You could use Asyn Callback to invoke webservice. This way the client could initiate a request for feedback. I do not believe we can achieve the other way round.
You will find more information on Asyn callback on How to: Implement an Asynchronous Web Service Client Using the Callback Technique
The best option is probably to have the Web Method return a string with whatever values you wanted to print to the console. The Console.WriteLine then needs to happen from the Console Applications side. Remember that you can return Objects/Classes/Xml from your Web Method as well, so you are not limited to a single string.
The other option will only really work if you have access to the Web Server running the Web Service. But then you would approach it by letting the Web Service write logs to a text file on the server. The appropriate IUSR_CompName needs write access to the folder on the computer then.