none
How to end ServicePoint->BindIPEndPointDelegate loop RRS feed

  • Question

  • I know servicepoint bind delegate and huge number of retries when binding fail.

    Question is when we know there is no network available, how to get out from these retries?

    We tried to return AnyIP but does not work. It still calls BindIP callback.

    httpReq.ServicePoint.BindIPEndPointDelegate = new BindIPEndPoint(BindIPAddress);

    private IPEndPoint BindIPAddress(ServicePoint servicePoint, IPEndPoint remoteEndPoint, int retryCount)
            {
                if (m_endPoint == null)
                    return new IPEndPoint(IPAddress.Any, 0);
                else
                {
                    if (retryCount >= 2)
                    {
                        ShoreTrace.TraceLn("Network connection via " + m_endPoint.Address.ToString() + " is not availble. Trying any IP");
                        return new IPEndPoint(IPAddress.Any, 0);
                    }
                    return m_endPoint;
                }
            }

    Wednesday, May 15, 2013 7:05 PM

Answers

  • Hi Ashvin,

    So far I haven't found any managed .NET framework API for abort the execution of the binding delegation. I think the runtime just simply invoke all the handler functions registered on the delegate property. Since you've already added code to detect network availability changes, you can consider defining some custom global status property which can be accessed in your custom "BindIPAddress" delegate function. Thus, the retry code can check the status property on each retry loop and exit the retry loop if network becomes not available.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, May 21, 2013 7:24 AM
    Moderator

All replies

  • Hi Ashvin,

    According to the MSDN document, there isn't additional properties on the ServicePoint class which provides further configuration options for the ip address binding delegate. Since you're using webrequest class to perform some web resource accessing task, it is ok that we use the NetworkInformation.NetworkChange class to detect network availability change and stop/avoid the webrequest calls when network is not available.

    #NetworkChange Class
    http://msdn.microsoft.com/en-us/library/system.net.networkinformation.networkchange.aspx


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, May 20, 2013 7:27 AM
    Moderator
  • Yes, My application knows network connection status so on next request I can avoid registering this callback but for current request (Network can fail in between) it will do max retry and There is no way to abort that correct?
    Monday, May 20, 2013 2:07 PM
  • Hi Ashvin,

    So far I haven't found any managed .NET framework API for abort the execution of the binding delegation. I think the runtime just simply invoke all the handler functions registered on the delegate property. Since you've already added code to detect network availability changes, you can consider defining some custom global status property which can be accessed in your custom "BindIPAddress" delegate function. Thus, the retry code can check the status property on each retry loop and exit the retry loop if network becomes not available.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, May 21, 2013 7:24 AM
    Moderator