简体   繁体   中英

How do you debug an WCF issue?

I'm running into a weird issue with my WCF Service using WS binding. When I configure it with no sessions (security/reliable) it works just fine, but not so with sessions. For example when I configure with security (message security, windows credentials), I get a timeout after 10th or 11th call. My service calls another WCF Service but, but both services are configured with same binding parameters.

How would you debug an issue like this? What tools would you use other than turning on tracing and using SvcTraceViewer?

One of the easiest areas to lose lots of time on while developing WCF services is in binding configuration. Backup your working configs religiously, for starters, in the source code repository. You may also want to add a validation routine for config file itself that runs prior to service creation.

As far as debugging such WCF issues, there really is no substitute for the good old Trace.WriteLine() that write to a TraceListener that is mapped to a file, on the service and in the client. But really, considering your issue is rather common and is most likely 100% config-related, I would suggest learning more about the binding settings, particularly timeouts. Set values to arbitrarily high numbers or even to the Timeout.Infinite numeric value (as a string), which will literally tell WCF to allow for an infinite timeout. Then, ask yourself, why something would be timing out that does not do so with just a slight change in the binding.

Regarding you specific issue, it is possible that sessions are not being terminated properly because client proxies are not being closed properly by calling the Close() method explicitly. You might be able to get away with this when you are dealing with sessionless bindings, but sessions will not be released unless you close the proxy. The side effect of this would be that the default service throttling values of usually 10 concurrent sessions will be reached. Once you understand the life cycle of a session, you might want to look into the IsInitiating, IsTerminating and IsOneWay properties that can be specified for OperationContract attributes on the methods of the service contract.

Here are a few useful resources:

OperationContract: (strange url that won't link)
http://en.csharp-online.net/WCF_Services —OperationContract_Attribute

Using Sessions:
http://msdn.microsoft.com/en-us/library/ms733040.aspx

A Handy Summary of WCF sessions, instancing, and reliable messaging
http://www.pluralsight.com/community/blogs/aaron/archive/2006/02/27/19253.aspx

And, as mentioned by Brian, my response to a throttling question:
WCF Service Throttling

The best way to debug such scenario would be to activate tracing in the WCF service/client. The tracer creates log files which you can use the build-in trace viewer to read. http://msdn.microsoft.com/en-us/library/ms733025.aspx

Sounds like you may be hitting a throttle...

WCF Service Throttling

http://kennyw.com/indigo/150

不要忘记从客户端调用代理上的.Close()方法。

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