2

I have a question with regards to WCF client channel lifetime while using Message security, but first, a few notes on my company's setup and guidelines:

  • Our client-server applications are solely for intranet use
  • Our clients are WPF applications
  • Our company's guidelines for WCF usage are:
    • Use wsHttpBinding
    • Use Message Security
    • Service InstanceMode: PerCall
    • Service ConcurrencyMode: Multiple

It is the first time I have to use message security on an intranet setup. Here's how I typically use my client channels to limit the amount of resources kept on the client and server and literally just to keep things simple:

  1. Instantiate + open channel (with ChannelFactory)
  2. Make the WCF call
  3. Close / dispose the channel asap

While monitoring this strategy with Fiddler 2, I noticed that because of Message Security, a single WCF call ended up causing 5 round-trips to my service:

  • 3 initial round-trips for handshaking
  • 1 round-trip for the actual WCF call
  • 1 call to close the session (since I am using PerCall, I am assuming this is more a security session at the IIS level)

If I were to turn off Message Security, as one would expect, one WCF ended up being... A single round-trip.

As of now, I must use Message Security because that's our guideline. With this in mind and knowing that we make hundreds of WCF calls from each client WPF app a session, would you therefore advise to open the client channel and keep it open for re-use instead of disposing of it every time?

Talisker
  • 177
  • 2
  • 16

1 Answers1

1

I would advise not to preemptively turn off features until you know they are a known problem. Preoptimization is needless work. Until you notice your clients having lagging problems, I would not worry about the message security. At that point, try a few things: one of your approaches of keeping a client open longer; two, try grouping requests together without turning off message security; three, consider caching, if you can; four, if the message security is the final culprit, then try a different method. I wouldn't just turn something off because I see a bit more network traffic until I knew it was the absolute last thing that I could do to improve performance.

Josh
  • 10,352
  • 12
  • 58
  • 109
  • Thanks for your answer. My question might not have been 100% clear. As of now, I **must** use Message Security, because that's the guideline. With this in mind, doing hundreds of WCF calls from the WPF client app each session, would it make more sense to keep client channel open or close it each time, incurring **many** more round trips than seem necessary.You have a good point about optimizing only when signs show it's necessary. I should create a test project and measure 100 or 1000 calls with the two strategies and see if there's really a hit... – Talisker Apr 19 '13 at 14:29
  • @sim Yeah, really only can answer that question after you run your tests. Like I said, try some tests, look for opportunities to group calls, check for caching, etc. I wouldn't just blanket turn on single call until I was absolutely sure that was the only thing left to change. To give you an idea, I'm in the same boat as you and we haven't had any problems with Message Security and doing a per-call instance creation...and we are talking thousands of calls. But your situation may be different. – Josh Apr 19 '13 at 15:35