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

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.