Consuming WCF Service (nettcp) from Asp.net core using WCF client library

826 views Asked by At

We have a WCF service hosted as nettcp mode and WCF client library, both services and client has been created using .net framework.

Now we are creating new application using Asp.net core 2.1, still here we need to consume the above created WCF Service using the same old WCF client Library.

Added this WCFClient library reference(.net framework) into our Asp.net core application. Here am using the below proxy constructor to pass my end point details.

public LoggingServiceProxy(Binding binding, EndpointAddress remoteAddress)
            : base(binding, remoteAddress)

new LoggingServiceProxy(new EndpointAddress("net.tcp://localhost:9100/LoggingService/Tcp"), new NetTcpBinding(SecurityMode.None));

After adding System.ServiceModel.NetTcp and System.ServiceModel.Primitives NUGET references, resolved all other errors. But code thread aborted abruptly when it executes the proxy code

((ICommunicationObject)this.channel).Open();

No more information, debug message available after this point. No exception raised.So we have no clue on what is it?

Note: When I stop my service to test, I clearly get exception "EndPointNotFound".

Expected behaviour is to able to consume the service from Asp.net Core application -> WCF Client Library(.net framework) -> WCF Service nettcp (.net framework)

After did more dig into the auto generated proxy code, found that this issue is happening in the event of InnerChannel_Opened() and InnerChannel_Closed() Above event got the following line of code "lock (this.channelLock)" which causes the issue. No exception raised. simply thread aborted/exited. When comment it out these events, it works fine, but am not too sure whether it is ok to comment these auto generated code.

               lock (this.channelLock)
                {
                    if (this.IsDisposed)
                    {
                        throw new InvalidOperationException("Cannot use disposed object.");
                    }

                    if (this.Opened != null)
                    {
                        this.Opened(sender, e);
                    }
                }
0

There are 0 answers