9

When adding a connected service in .net core 2.0 using the WCF Web Service Reference provider to a SOAP interface the System.ServiceModel.ClientBase version 4.2.0.0 no longer has the IDisposable interface found in version 4.0.0.0.

This means I can no longer wrap it in a using statement (or use try/finally and dispose of the object) like so:

using (MyClass.MyClassSoapClient client = new MyClass.MyClassSoapClient(EndpointConfiguration.MyClassSoap))

I can't figure out why IDisposable was removed and whether I should attempt to implement it myself, or if the intention is for me to use the SOAP interface in a different manner in .net core?

Tarostar
  • 1,196
  • 1
  • 15
  • 27
  • Did you ever find out how to do this? – Sturla Jan 02 '18 at 16:24
  • I found out what to do. You should use wcf differently now in .net core http://tattoocoder.com/asp-net-core-getting-clean-with-soap/ – Sturla Jan 02 '18 at 17:30
  • I ended up using a try/catch/finally insteading of "using" and calling "Close" in finally on the client: MyClass.MyClassSoapClient client = new MyClass.MyClassSoapClient(EndpointConfiguration.MyClassSoap); try { // use client } catch (Exception e) { logger.Error("MyClassSoapClient exception" + e.Message); } finally { ((ICommunicationObject)client).Close(); } – Tarostar Jan 03 '18 at 05:35
  • 2
    You should actually never have wrapped it in a using because it could throw exceptions: https://stackoverflow.com/questions/573872/what-is-the-best-workaround-for-the-wcf-client-using-block-issue – xr280xr Jun 29 '20 at 21:33
  • Indeed, I feel like using is a bit of a trap. – Tarostar Jun 30 '20 at 15:19

0 Answers0