Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7911001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:05:00+00:00 2026-06-03T13:05:00+00:00

I have inherited a WCF service which acts as a file cache (each file

  • 0

I have inherited a WCF service which acts as a file cache (each file representing the results of a request to a third party API). At the moment if the file doesn’t exist the code creates a new request to create the data and it also raises an exception to the client code.

I think the idea is that the clients would come back to request the file again and by then it would be available by them (it takes a couple of seconds to generate the file).

I think there’s a code smell here and I should rewrite this part. At the moment the exception is getting caught and bubbled up through a couple of methods. I think I should be establishing at source whether the file exists and pass that information up the call stack.

At the WCF interface I currently have a GetValue() method, though there are two options I think I could use to replace it:

  1. return null if the file does not exist.
  2. Use a bool TryGetValue(string key, out string value) method

Does anyone have any preferences/recommendations?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T13:05:02+00:00Added an answer on June 3, 2026 at 1:05 pm

    The “TryGet” approach is a little more explicit. With the null-returning approach, you have to document that the method returns null for such and such a reason, and this requires developers to read the documentation. As we all know, some people are allergic to reading documentation.

    Another advantage of the “TryGet” approach is that you can use an enum rather than a bool, to give even more information to the caller about why and how the method failed (or succeeded).

    Jeffrey Richter’s (CLR in C#) definition of an exception: When an action member cannot complete its task, the member should throw an exception. An exception means that an action member failed to complete the task it was supposed to perform as indicated by its name. My question is should I keep the GetValue method available for the client and raise an error when the data is unavailable or remove it and replace it with TryGetValue()?

    Jeffrey Richter’s definition is not helpful when you are determining the design of your API, because that includes determining what the tasks of each action member should be.

    In your design, you are expecting the value to be unavailable as a matter of course; this means that it is not an exceptional situation for the value to be unavailable. I would therefore use only the TryGet… pattern.

    But, truth be told, I would pursue a different approach altogether. Suppose somebody tries this approach:

    while (!TryGetValue(key, out value)) {}
    

    or:

    SomeType value;
    bool flag = false;
    while (!flag)
    {
        try
        {
            value = GetValue(key);
            flag = true;
         }
         catch {}
    }
    

    Your WCF service is going to get a lot of hits. It would probably be better to look into an asynchronous model, so the client is notified through a callback when the result is ready, rather than inviting the client to poll the service continually.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a wcf service which provide a main configuration to all the other
I have converted my web service to wcf service which has some datacontracts. As
I have inherited some code that queries a DB over a WCF service and
I have a method in a WCF service which returns a complex type (myComplexResult),
I have a WCF Web Service which is referenced from a class library. After
I have a Silverlight application which interacts with a WCF service. It periodically receives
I have a service, which inserts stuff into MSMQ via WCF. However, it can
All, I have a WCF Service I inherited from someone else. When I make
I have a wcf service. The service itself (class that inherits the ServiceContract )
I have inherited couple of .Net (C#) application which does not have any tracing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.