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

16 Replies

Replies have been turned off for this discussion
  • kjm's avatar
    kjm
    Trusted Cover User
    3 years ago

    Hi Mike_James 

     

    you've pointed me to the apisupport page? not sure what you are referring to by that link..? Iahave seen it and read it.. are  you referring to the refresh token timout How long do access tokens & refresh tokens last? – Support for the MYOB family of SME product APIs

     

    I know it is a week but not really the same as 

    Client Credentials Flow (auth0.com)

    or 

    RFC 6749: The OAuth 2.0 Authorization Framework (rfc-editor.org)

     

    which are really what I am hoping for...

     

    apologies if I have misunderstood...

  • kjm's avatar
    kjm
    Trusted Cover User
    3 years ago

    Mike_James 

     

    I appreciate any help/reply...certainly no need to apologise. :)

     

    I wasnt aware the refresh token was for a week until I followed your link and did a search..lol

     

    It would be great if MYOB could implement either the spec for client credentials flow as per Oauth2 or extend the refresh token to a month perhaps?

     

    Any idea if the MYOB API developers read these forums? would be good to know what the plans are 

     

     

  • kjm's avatar
    kjm
    Trusted Cover User
    3 years ago

    The_Doc 

     

    yes that is what is described in their help 

    How long do access tokens & refresh tokens last? – Support for the MYOB family of SME product APIs

     

    Get an access token and then keep using the refreh token for 7 days.

     

    My issue ( and from quite a few other devs on the forum) is that along with apps used by humans we have background jobs running on schedules doing a variety of tasks

     

    These, as the name suggests, run in the background without human intervention on servers etc. 

     

    OAuth2 spec accomodates this by use of client credential flow as link above in my other post

     

    My issue is it would be great if myob would allow this credential flow so that I would not need to remote into server every 7 days to login. Not the end of the world but not ideal either

     

    Peronally/imo setting the refresh token to to 1 year does not sound like it was ever a good idea..I know it is now 7 days but I think they were trying to use the refresh token (1year) to accomodate the client credential flow instead of implementing the actual client credential flow

     

    completely my opinion only I am not basing that on any facts/info

     

    If more than myself request this (and I know there are more than myself in this situation running background jobs) from myob we might have a chance they will actually look at implementing it

     

     

     

     

     

  • The_Doc's avatar
    The_Doc
    Ultimate Cover User
    3 years ago

    Hi kjm 

     

    Am I missing something here - I too have systems running on servers that do not require human intervention - oh it might hang or the service gets a problem with the API - but I never have had to input logon details for over a year.

     

    i.e. so long as you use the refresh token to get an access token under 7 days then no intervention is needed.

     

    Unless of course you only need a task done at intervals greater than 7 days then yes you would need to logon - why not just build a task to refresh every < 7 days.

     

    regards Howard

  • kjm's avatar
    kjm
    Trusted Cover User
    3 years ago

    The_Doc ok...that would be good. I have not tried letting it run for 7 days to see if a new access token is recieved. didnt realise that is what it did 

     

    that would solve my issues...thanks for that :)

Looking for something else?

Search the Community Forum for answers or find your topic and get the conversation started!

Community home

Dig into MYOB Academy for free courses, learning paths and live events to help build your business with MYOB.