0

I am attempting to use this workaround for correctly disposing a WCF client so I can wrap the call to client in using statement.

So at my integration layer I added a Service Reference and gave svc address of where my external Service is located.

That created a folder within Service References MyExternalService which contains MyExternalService.disco, MyExternalService.wsdl, Reference.svcmap, etc

Within the Service Reference Folder I created a class called MyExternalServiceClient as below:

public partial class MyExternalServiceClient : IDisposable
{
    void IDisposable.Dispose()
    {
        bool success = false;
        try
        {
            if (State != CommunicationState.Faulted)
            {
                Close();
                success = true;
            }
        }
        finally
        {
            if (!success)
            {
                Abort();
            }
        }
    }
}

The problem I am having is that resharper is telling me partial class with a single part. And the State Close and Abort symbols cannot be resolved - even with this.State - the using statements I have at the top of my class are:

using System;
using System.ServiceModel;
Community
  • 1
  • 1
Ctrl_Alt_Defeat
  • 3,933
  • 12
  • 66
  • 116

1 Answers1

2

Make sure:

  1. The partial class definition is in the same assembly

  2. You're using the namespace of your service reference:

Example:

namespace XXX.YYY.ZZZMyExternalServiceOrWhatever
{
    /// <summary>
    /// Partial definition of MyExternalServiceClient.
    /// </summary>
    public partial class MyExternalServiceClient : IDisposable
    {
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        void IDisposable.Dispose()
        {
            bool success = false;
            try
            {
                if (this.State != CommunicationState.Faulted)
                {
                    this.Close();
                    success = true;
                }
            }
            finally
            {
                if (!success)
                {
                    this.Abort();
                }
            }
        }
    }
}
ken2k
  • 48,145
  • 10
  • 116
  • 176