Retrieve a host service instance ID

You can retrieve a host service instance ID for a component that can be configured to support high availability. Components that cannot be configured to support high availability have only a service instance. The following code sample retrieves a Dispatcher host service instance.
Before you begin: Retrieve the following variables:
  • serviceID integer for the service ID that you want to find a host service instance of
  • instanceName string for the name of the host service instance that you want to find
  1. Create an integer to store the host service instance ID.
    int hostServiceInstanceID;
  2. Invoke findServiceInstancesByService().
    FindServiceInstancesByService request = new findServiceInstancesByService();
    request.serviceId = serviceID;
    request.locale = locale;
    request.includeStatus = false;
    request.includeExtendedData=true;
    request.loadServiceConsumerRelationships=false;
    request.loadServiceConsumerRelationships=false;
    FindServiceInstancesByServiceResponse response = coreWebService.findServiceInstancesByService(request);
  3. Check the result for errors and handle any errors.
    if (result.findServiceInstancesByServiceReturnStatus.code != FindServiceInstancesByServiceReturnStatusEnumType.SUCCESS) 
    {    
    	    // handle any errors
    } 
  4. Loop through the result until you find the host service instance that you want to retrieve the ID for
    for (int j = 0; j < serviceInstanceResult.serviceInstances.Length; j++)
    {
        if (serviceInstanceResult.serviceInstances[j].GetType().Equals(typeof(DispatcherHostServiceInstance)))
        {
            if (serviceInstanceResult.serviceInstances[j].name.ToUpper().Equals(instanceName.ToUpper()))
            {
                hostServiceInstanceID = serviceInstanceResult.serviceInstances[j].serviceId;
                break;
            }
        }
    }

Was this information helpful? Send us your comments.