Forum Discussion

kjm's avatar
kjm
Trusted Cover User
3 years ago

Socket Exhaustion and the MYOB .NET SDK

I am developing our inhouse application to go online using the MYOB .NET SDK to go live for STP2 in Jan

 

I have looked at the .NET SDK Code from GitHub and for the API calls it uses a HttpWebRequest Object in the WebRequestFactory.cs class. As I see it each call will create a new HttpWebRequest object  and eventually exhause the available ports.  Have I got this right? shouldnt the request be made from a static reused object? instead of creating a new instance the whole time? Isnt this prone to socket/port exhaustion? There is a lot of documentation around now specifying that. Mostly surrounding HttpClient and using it as a static object

Has anyone experienced this? I am not planning to make many calls per second. Probably never more than 2-3 at the most heaviest load

 

 public virtual WebRequest Create(Uri requestUri, string acceptEncoding = null)
        {
            var webrequest = (HttpWebRequest)WebRequest.Create(requestUri);
            webrequest.Accept = acceptEncoding;

#if !PORTABLE
            webrequest.CachePolicy = _configuration.RequestCachePolicy;
            webrequest.Timeout = 180000;
#endif

            return webrequest;
        }

static WebRequestFactory()
        {
            SharedWebRequestFactory = null;
        }

        /// <summary>
        /// Get the SharedWebRequestFactory
        /// </summary>
        public static IWebRequestFactory SharedWebRequestFactory { get; private set; }

        /// <summary>
        /// Get the SharedWebRequestFactory - implemented this way to avoid accidental assignment
        /// </summary>
        /// <param name="factory"></param>
        public static void SetSharedWebRequestFactory(IWebRequestFactory factory)
        {
            SharedWebRequestFactory = factory;
        }
        #endregion


There is a reference in the class to the static SharedWebRequestFactory. Is this the part that gets reused?

 

I am interested to hear other dev experience and if this has been an issue with the SDK and wether I should leave the SDK and develop my own requests using HttpClient 

Are the devs out there using the .NET SDK successfully and not experienceing any issuse like this? What are the max requests to the SDK that you ar eputting it thru?

PhilWherrett mentioning you here as I know you ar ein a similar position and wondered what your thoughts are. Tried messaging you but you have PM turned off

  • The_Doc's avatar
    The_Doc
    Ultimate Cover User

    Hi kjm 

     

    I think this post is best on the specific API forum board.

     

    Having said that, I have never really used it and have gone directly to the developers email which I haven't used since 1 Jul as we now need a code.

    Further - I (and I cannot speak for any others) never used the SDKs - I did get the VB.NET version working - couldn't get the VC#.NET version working - though at the time I was a VB.NET person - but 2 years on am now converted to C#.NET but have no interest in using the SDK.

     

    As such I developed in MSAccess VBA ALL my own access protocols and codes and have been using this perfectly since then.

     

    Yes the HttpClient in VBA works perfectly - but once you step outside the MYOB SDK you have to then code everything yourself and all the security overlays - and that wasn't easy.

     

    All I have spoken to did similar with their own favorite language.

     

    As part of my rainy day projects is to revisit the MYOB SDK to see if I can now get **bleep** going

     

    Regards The Doc

    • kjm's avatar
      kjm
      Trusted Cover User

      Hi The_Doc 

       

      thanks for your reply..Isnt this the API forums? ...that would explain some things ...lol

       

      I've had the c# SDK working for a couple years now...no major problems..porting it to the cloud is not really an issue either..beside there being a bug in OAuthService whic gets the access token but have built my own classes to retrieve that. My main issue is I have to stop usng the SDK I wil need to rebuild that using RestSharp or HttpClientFactory and OData...not overly difficult just a little time consuming..

       

      can you point me to the API forum I am meant to be using ? thanks :)

      • The_Doc's avatar
        The_Doc
        Ultimate Cover User

        Hi kjm 

         

        Can't give exact API forum but it isn't very active hence why I don't go there - but I think from the following web you should find it somehow.

         

        https://developer.myob.com/

         

        Yes you will have to write your own classes but having done that you don't need to worry about bugs in MYOB's SDK which are not singular.

         

        As all my code is in VBA access - and it just works - creating my own classes in C# is another rainy day project.

         

        I had envisaged writing my own specifically for MYOB and calling them from Access for the connection but again not needed. Just more work.

         

        Access is just a whole lot more powerful as a database product than C# on its own - even though C# as a language is extra-ordinarily powerful - way more than Access but C3 just doesn't have the ability to handle local tables as per Access.

         

        When C# then we will have a very powerful OOP language.

         

        regards The Doc

  • PhilWherrett's avatar
    PhilWherrett
    Experienced User

    Hi kjm ,

     

    Sorry for the slow reply - been sidetracked on another project :-).

     

    We've been using the .NET SDK for years.  C# Console apps that run via Scheduled Tasks.  The main purpose is to extract data from MYOB and import into a SQL Data Warehouse.

     

    We see random communication error exceptions and have just been dealing with them by re-trying our tasks a number of times.  Whether this is related to the socket exhaustion - we haven't investigated to find out.

     

    Cheers,

    Phil.

    • kjm's avatar
      kjm
      Trusted Cover User

      PhilWherrett 

      I use c#/Hangfire to run jobs overnight etc ... not unlike your consol app/schedule task setup

       

      How are you doing this? are you manually logging in each time a scheduled task runs?

       

      As I understand it myob has not allowed oauth flow for software clients without user interaction?

      • PhilWherrett's avatar
        PhilWherrett
        Experienced User

        Hi kjm ,

         

        Until now, we have had our datafile on-premises so have not had to worry about OAuth.

        As STP Phase 2 requires the datafile to be in the cloud, that's changing.  I'm in the process of testing whether I can get the token(s) initially by user interaction, and then persist and rely on the lifetime of the refresh token to obtain further access tokens without requiring any further user interaction.

         

        Cheers,

        Phil.