title: Generics program to access WCF service from client
body: <p>Please look at the below code where a client is accessing WCF service</p>
  
  <p><strong>Function GetPriority</strong></p>
  
  <pre><code>public List&lt;Priority&gt; GetPriority()
          {
              List&lt;Priority&gt; lstPriority = new List&lt;Priority&gt;();
  
              using (TmsServiceClient client = new TmsServiceClient())
              {
                  try
                  {
                      lstPriority =  client.GetPriority();
                  }
                  catch (FaultException&lt;TMSCustomException&gt; myFault)
                  {
                      Console.WriteLine(myFault.Detail.ExceptionMessage);
                      client.Abort();
                  }
                  catch (Exception ex)
                  {
                      Console.WriteLine(ex.Message);
                      client.Abort();                  
                  }
              }
              return lstPriority;
          }
  </code></pre>
  
  <p><strong>Function GetStatus:</strong></p>
  
  <pre><code>public List&lt;Status&gt; GetStatus()
      {
          List&lt;Status&gt; lstStatus = new List&lt;Status&gt;();
          using (TmsServiceClient client = new TmsServiceClient())
          {
              try
              {
                  lstStatus =  client.GetStatus();
              }
              catch (FaultException&lt;TMSCustomException&gt; myFault)
              {
                  Console.WriteLine(myFault.Detail.ExceptionMessage);
                  client.Abort();                   
              }
              catch (Exception ex)
              {
                  Console.WriteLine(ex.Message);
                  client.Abort();                   
              }
          }
  
          return lstStatus;
      }
  </code></pre>
  
  <p>Both the methods are working fine. As can be seen that there are many similarities between the two methods and they differ only at the time of method invocation and return type. Can this be make generic? If so how to do so? Or any other better way so that the catch exception block code should not be repeated everytime.</p>
  
  <p>Thanks in advance</p>