bgmulinari / B1SLayer

A lightweight SAP Business One Service Layer client for .NET
MIT License
122 stars 42 forks source link

Working with multiple instances doesn't work #37

Closed WitmondPaul closed 1 year ago

WitmondPaul commented 1 year ago

Hi Bruno,

When we connect 2 or more companies using B1Slayer the eventhandling is only working on the last connected company

Example :

B1Connection = new SLConnection(serviceLayerRoot, "LEEG", "manager", "demo"); B1Connection.AfterCall(async call => { TextOk("AC :"+ $"Response: {call.HttpResponseMessage?.StatusCode}"); ResponseBody = await call.HttpResponseMessage?.Content?.ReadAsStringAsync();

        });
        B1Connection.OnError(async err =>
        {
            ErrorBody = await err.HttpResponseMessage?.Content?.ReadAsStringAsync();
        });

        B1Connection2 = new SLConnection(serviceLayerRoot, "SBODEMONL", "manager", "demo");
        B1Connection2.AfterCall(async call2 =>
        {
            ResponseBody2 = await call2.HttpResponseMessage?.Content?.ReadAsStringAsync();
            TextOk("AC2 :" + $"Response: {call2.HttpResponseMessage?.StatusCode}");
        });
        B1Connection2.OnError(async err2 =>
        {
            ErrorBody2 = await err2.HttpResponseMessage?.Content?.ReadAsStringAsync();
        });

In this example the Aftercall event of the first connection doesn't work. If we remove the 2nd the eventhandling on the first company is working fine.

Can this be solved ?

Regards,

Paul

bgmulinari commented 1 year ago

Hi, @WitmondPaul. This can be a bit confusing, but I'll try my best to explain.

The methods BeforeCall, AfterCall and OnError work by setting a global callback that is invoked for every request to a given base Service Layer URL.

So, for instance, if your Service Layer URL is https://yourserver:50000/b1s/v1, all requests made to https://yourserver:50000 should invoke the callback you specified.

In other words, if for both of your SLConnection instances the Service Layer URL is the same, you only need to implement a single callback (in either instance) and it should be called for requests for both instances. If the URL is different, then it makes sense to set it sepparetly like you're doing, otherwise the last callback will overwrite the previous ones like you're seeing, since the URL is the same.

WitmondPaul commented 1 year ago

Hi Bruno,

Thanks, this is clear and working.

Best regards / Met vriendelijke groet,

Paul Witmond

Planlogic B.V. | Bolderweg 2 | 1332 AT Almere | T. +31 (0)36 3030003| M. +31 (0)627 096 016| KvK 11033102 @.*** Volg ons online: www.planlogic.nlhttp://www.planlogic.nl/ | LinkedInhttps://www.linkedin.com/company/planlogic-b-v- | Facebookhttps://www.facebook.com/PlanlogicNederland/

The contents of this message, as well as any enclosures, are addressed personally to, and thus solely intended for the addressee. They may contain information regarding a third party. Any recipient who is neither the addressee, nor empowered to receive this message on behalf of the addressee, is kindly requested to immediately inform the sender of receipt. Any use of the contents of this message and/or of the enclosures by any other person than the addressee is illegal towards the sender and the aforementioned third party. Always scan attachments before opening them.

Van: Bruno Mulinari @.> Verzonden: vrijdag 14 april 2023 16:55 Aan: bgmulinari/B1SLayer @.> CC: Paul Witmond | Planlogic @.>; Mention @.> Onderwerp: Re: [bgmulinari/B1SLayer] Working with multiple instances doesn't work (Issue #37)

Hi, @WitmondPaulhttps://github.com/WitmondPaul. This can be a bit confusing, but I'll try my best to explain.

The methods BeforeCall, AfterCall and OnError work by setting a global callback that is invoked for every request to a given base Service Layer URL.

So, for instance, if your Service Layer URL is https://yourserver:50000/b1s/v1, all requests made to https://yourserver:50000 should invoke the callback you specified.

In other words, if for both of your SLConnection instances the Service Layer URL is the same, you only need to implement a single callback (in either instance) and it should be called for requests for both instances. If the URL is different, then it makes sense to set it sepparetly like you're doing, otherwise the last callback will overwrite the previous ones like you're seeing, since the URL is the same.

— Reply to this email directly, view it on GitHubhttps://github.com/bgmulinari/B1SLayer/issues/37#issuecomment-1508704568, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A4LY3PFTETFSZQR4LGRHIHDXBFQLJANCNFSM6AAAAAAW6KN3TM. You are receiving this because you were mentioned.Message ID: @.**@.>>