Code-Sharp / WampSharp

A C# implementation of WAMP (The Web Application Messaging Protocol)
http://wampsharp.net
Other
384 stars 84 forks source link

How to handle wamp.error.procedure_already_exists when callee reconnects? #332

Closed jcam7044 closed 3 years ago

jcam7044 commented 3 years ago

Hoping someone can advise me on how to best handle reconnections for clients connecting as callees. The problem I am running into is when a callee client loses its connection to the router. I have logic that reconnects the client to the router but when I try to register the callee procedures again I get a wamp.error.procedure_already_exists error. If I try to reconnect without registering again(using WampChannelReconnector) any RPC calls from a caller never finds the callee again. (I think this is because of a different session id? I'm not really sure here.)

Is there a way I can unregister the callee from the router or have new registrations override existing registrations?

Below is connection logic.

`var factory = new WampChannelFactory();
                IWampClientAuthenticator authenticator = new TicketAuthenticator(_agentId, _agentSecret);
                channel = factory
                            .ConnectToRealm(_agentId)
                            .WebSocketTransport(name => new WebSocket(_wsUrl, subProtocol: name, origin: ConvertToHttpsString(_wsUrl)))
                            .SetSecurityOptions(o =>
                            {
                                o.EnabledSslProtocols = SslProtocols.Tls12;
                                o.AllowCertificateChainErrors = false;
                                o.AllowNameMismatchCertificate = false;
                                o.AllowUnstrustedCertificate = false;
                            })
                            .JsonSerialization()
                            .Authenticator(authenticator)
                            .Build();
                ServicePointManager.ServerCertificateValidationCallback = (s, crt, chain, policy) => true;

                await channel.Open().ConfigureAwait(false);`

Thanks

darkl commented 3 years ago

You can solve this by registering with RegisterOptions having Invoke= WampInvokePolicy.Last.

Elad

On Thu, Apr 22, 2021, 16:39 Jason Cameron @.***> wrote:

Hoping someone can advise me on how to best handle reconnections for clients connecting as callees. The problem I am running into is when a callee client loses its connection to the router. I have logic that reconnects the client to the router but when I try to register the callee procedures again I get a wamp.error.procedure_already_exists error. If I try to reconnect without registering again(using WampChannelReconnector) any RPC calls from a caller never finds the callee again. (I think this is because of a different session id? I'm not really sure here.)

Is there a way I can unregister the callee from the router or have new registrations override existing registrations?

Below is connection logic.

`var factory = new WampChannelFactory(); IWampClientAuthenticator authenticator = new TicketAuthenticator(_agentId, _agentSecret); channel = factory .ConnectToRealm(_agentId) .WebSocketTransport(name => new WebSocket(_wsUrl, subProtocol: name, origin: ConvertToHttpsString(_wsUrl))) .SetSecurityOptions(o => { o.EnabledSslProtocols = SslProtocols.Tls12; o.AllowCertificateChainErrors = false; o.AllowNameMismatchCertificate = false; o.AllowUnstrustedCertificate = false; }) .JsonSerialization() .Authenticator(authenticator) .Build(); ServicePointManager.ServerCertificateValidationCallback = (s, crt, chain, policy) => true;

        await channel.Open().ConfigureAwait(false);`

Thanks

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Code-Sharp/WampSharp/issues/332, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAIS75W26SJEHQM6PZHDCITTKCCRZANCNFSM43NKKUNA .

jcam7044 commented 3 years ago

Thanks Elad. Is done on the client or the router?

darkl commented 3 years ago

Wherever you register your Callee (probably client side).

Elad

On Thu, Apr 22, 2021, 16:47 Jason Cameron @.***> wrote:

Thanks Elad. Is done on the client or the router?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Code-Sharp/WampSharp/issues/332#issuecomment-825174333, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAIS75XCHFDH755MAKRVNGLTKCDOPANCNFSM43NKKUNA .

jcam7044 commented 3 years ago

Got it. Thank you so much Elad!