简体   繁体   中英

How to debug a WCF service?

I have a WCF Restful service hosted in my windows application.

The clients to the service are mobile applications.

The clients call the service and messages are passed to the application and work is executed.

The issue that i am facing is that the application works fine in most of the cases. But it doesnt work on some machines and network settings.

To give a better idea : The app is not working on machine 1 connected to router A. Now as i change and connect it to router B, the same app starts working on the same machine.

Similarly, the app is not working on machine1 connected to router A. Now as i change the machine and remain connected to the same router, the app works fine.

I am not able to figure out the problem. Any idea on how to debug this issue?

Any help appreciated.

I would turn on tracing and message logging in the WCF service. This can be done in the web.config/app.config file of the service, most easily via the WCF Service Configuration tool in Visual Studio which is available under the tools menu (note: once you open this tool once, you will be able to close it and then right click on your app/web .config file and select 'edit WCF configuration' from the context menu for the duration of your Visual Studio session and have the file open automatically in the tool). On the WCF Configuration editor, navigate to the Diagnostics section and you can turn Tracing and Message logging on. Note where the log files are being created and/or adjust the path to a more desired location. I would also recommend turning on autoflush, so information is written to the logs more frequently. You may want to cycle the service after a tracing session to make sure that the log files contain all relevant information.

Now, hit the service from the non working configuration. Examine the logs using svctraceviewer.exe which you can find in your SDK folder under program files. See if anything jumps out at you in the logs, if not then purge the existing log files on the server and examine a set of log files from a valid session to attempt to contrast the differences.

Here is a link to msdn regarding WCF tracing which may be helpful: http://msdn.microsoft.com/en-us/library/ms730342.aspx

您可以尝试使用像Fiddler这样的工具来检查和比较在不同环境中交换的消息。

In order to achieve your purpose, you can enable tracing for your wcf service. There is already a link on stackoverflow for on this topic.

How to turn on WCF tracing?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM