tags:

views:

38

answers:

0

hi.

i have a web service client.

when I crate object of this service client it tries to connect to web service.

what i want to achieve is if the service does not respond, the client should retry to connect to service after specified time and this retires continue until MAX_RETRIES reaches.

how can i do this. client is in c# win-form.

here is the code

  public class OrgServiceClient
    {
        private UtilityServiceEndPointService orgService;
        private OrgXmlParser orgXmlParser;

        private bool isConnected;    

        public OrgServiceClient(string serviceUrl)
        {
            this.orgService = new UtilityServiceEndPointService();

            if (!string.IsNullOrEmpty(serviceUrl))
            {
                this.orgService.Url = serviceUrl;
            }
            if (this.isConnected == false)
            {
                this.ConnectoToService();
            }
        }

        private void ConnectoToService()
        {
            string xmlStringFlat = "";
            string xmlStringTree = "";
            try
            {
                // get tree and flat xml of organization structure including Location(s)
                xmlStringFlat = this.orgService.getCompleteOrgStructure(false, false, true, false);
                xmlStringTree = this.orgService.getCompleteOrgStructure(true, false, true, false);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception : {0} ", ex.Message);
                return;
            }

            this.orgXmlParser = new OrgXmlParser(xmlStringTree, xmlStringFlat);
            this.isConnected = true;
        }    

        public ElectronicAddress GetElectronicAddress(ushort orgId)
        {
            if (this.isConnected == true)
            {
                return this.orgXmlParser.GetElectronicAddress(orgId);
            }
            else
            {
                return null;
            }
        }    

        public List<Organization> OrganizationList
        {
            get
            {
                if (this.isConnected == true)
                {
                    return this.orgXmlParser.OrganizationList;
                }
                else
                {
                    return null;
                }
            }
        }    

        public Organization GetOrganization(ushort orgId)
        {
            if (this.isConnected == true)
            {
                return this.orgXmlParser.GetOrganization(orgId);
            }
            else
            {
                return null;
            }
        }

    }