Bug 15356 - NetTcpBinding Callback doesn't work
Summary: NetTcpBinding Callback doesn't work
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: WCF assemblies (show other bugs)
Version: 3.2.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2013-10-11 10:29 UTC by David Lambert
Modified: 2017-09-06 16:55 UTC (History)
2 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments

Description David Lambert 2013-10-11 10:29:27 UTC
https://bugzilla.novell.com/show_bug.cgi?id=718745

I'm experimenting the same thing apart from the fact that only one client is connected.
This exception is logged in console (same as the other bug report) Exception DispatchOperation '*' for contract 'IService' requires Invoker...

And I get this from

 Exception: System.Xml.XmlException
 Message: Expecting SynchronizationEndedResponse tag from namespace http://cloudsolutions/wimisyncservice/sync, got GetManagedFolders and http://cloudsolutions/wimisyncservice/sync instead
 StackTrace:   at System.Xml.XmlReader.ReadStartElement (System.String localname, System.String ns) [0x0007c] in /private/tmp/source/bockbuild-xamarin/profiles/mono-mac-xamarin/build-root/mono-3.2.3/mcs/class/System.XML/System.Xml/XmlReader.cs:795 
  at System.ServiceModel.Dispatcher.DataContractMessagesFormatter.MessageToParts (System.ServiceModel.Description.MessageDescription md, System.ServiceModel.Channels.Message message) [0x0003c] in /private/tmp/source/bockbuild-xamarin/profiles/mono-mac-xamarin/build-root/mono-3.2.3/mcs/class/System.ServiceModel/System.ServiceModel.Dispatcher/BaseMessagesFormatter.cs:411 
  at System.ServiceModel.Dispatcher.BaseMessagesFormatter.DeserializeReply (System.ServiceModel.Channels.Message message, System.Object[] parameters) [0x0004d] in /private/tmp/source/bockbuild-xamarin/profiles/mono-mac-xamarin/build-root/mono-3.2.3/mcs/class/System.ServiceModel/System.ServiceModel.Dispatcher/BaseMessagesFormatter.cs:272 
  at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeReply (System.ServiceModel.Channels.Message message, System.Object[] parameters) [0x00000] in /private/tmp/source/bockbuild-xamarin/profiles/mono-mac-xamarin/build-root/mono-3.2.3/mcs/class/System.ServiceModel/System.ServiceModel.Dispatcher/BaseMessagesFormatter.cs:91 
  at System.ServiceModel.MonoInternal.ClientRuntimeChannel.Request (System.ServiceModel.Description.OperationDescription od, System.Object[] parameters) [0x0024d] in /private/tmp/source/bockbuild-xamarin/profiles/mono-mac-xamarin/build-root/mono-3.2.3/mcs/class/System.ServiceModel/System.ServiceModel/ClientRuntimeChannel.cs:564 
  at System.ServiceModel.MonoInternal.ClientRuntimeChannel.DoProcess (System.Reflection.MethodBase method, System.String operationName, System.Object[] parameters) [0x00038] in /private/tmp/source/bockbuild-xamarin/profiles/mono-mac-xamarin/build-root/mono-3.2.3/mcs/class/System.ServiceModel/System.ServiceModel/ClientRuntimeChannel.cs:496 
  at System.ServiceModel.MonoInternal.ClientRuntimeChannel.Process (System.Reflection.MethodBase method, System.String operationName, System.Object[] parameters) [0x0001c] in /private/tmp/source/bockbuild-xamarin/profiles/mono-mac-xamarin/build-root/mono-3.2.3/mcs/class/System.ServiceModel/System.ServiceModel/ClientRuntimeChannel.cs:477 


If I set the callback methods as IsOneWay = true I get the same as https://bugzilla.xamarin.com/show_bug.cgi?id=14279 : it doesn't work without any trace.
Comment 1 David Lambert 2013-10-14 05:54:49 UTC
You can try the following code to partially reproduce. I don't see the dispatch operation exception in console but I get the same exception on the callback call. Execute the code and then in console press and hold any key and you'll get the error at some point.

With extra luck you'll get the "Exception Object of type 'System.ServiceModel.MonoInternal.DuplexServiceRuntimeChannel' doesn't match target type 'System.ServiceModel.IClientChannel'   at System.Reflection.MonoMethod.Invoke" exception also reported there https://bugzilla.xamarin.com/show_bug.cgi?id=11631 at app start.

using System;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.ServiceModel.Channels;

namespace Test
{
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, IncludeExceptionDetailInFaults = true)]
    public class MyService : IMyService
    {
        private IServiceCallback _callback;

        public void Register()
        {
            _callback = OperationContext.Current.GetCallbackChannel<IServiceCallback>();
        }

        public void DoWork(string host)
        {
            try
            {
                Console.WriteLine("Server is working!");
                _callback.OnDowork(host);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }

    [ServiceContract(CallbackContract = typeof(IServiceCallback))]
    public interface IMyService
    {
        [OperationContract]
        void Register();

        [OperationContract(IsOneWay=true)] 
        void DoWork(string host);
    }

    [ServiceContract] 
    public interface IServiceCallback
    {
        [OperationContract] 
        void OnDowork(string host);
    }

    public class ServiceCallback : IServiceCallback
    {
        public void OnDowork(string host)
        {
            Console.WriteLine(host + " got called back!");
        }
    }

    [CallbackBehavior()]
    class MainClass
    {
        const int Port = 60501;

        public static void Main(string[] args)
        {
            var host = new ServiceHost(typeof(MyService)); 
            var binding = new NetTcpBinding(); 
            binding.Security.Mode = SecurityMode.None; 
            host.AddServiceEndpoint(typeof(IMyService), binding, string.Format("net.tcp://localhost:{0}", Port)); 
            host.Open(); 
            Console.WriteLine("Service started ..."); 

            var callback = new ServiceCallback();
            var proxy = GetClientProxy(callback);
            proxy.Register();
            do
            {
                proxy.DoWork("Client");     
            } while (Console.ReadKey().Key != ConsoleKey.Q);	
            host.Close();
        }

        private static IMyService GetClientProxy(IServiceCallback callback)
        {
            var factory = new DuplexChannelFactory<IMyService>(callback, new NetTcpBinding(SecurityMode.None), string.Format("net.tcp://localhost:{0}", Port)); 
            return factory.CreateChannel(); 
        }
    }
}
Comment 2 David Lambert 2013-10-14 05:58:09 UTC
Actually in the example above, you should trigger the DispatchOperation exception and it will be logged in Console right after the Xml related exceptions.

Note You need to log in before you can comment on or make changes to this bug.