Identifying the API Version Supported by the Server
One approach to targeting multiple versions of the API from the same client application code is to check for the existence of the server versions file on the server. If you do not find a vimServiceVersions.xml file on the server, the server is older than ESX/ESXi 4.x, vCenter Server 4.x.
Example: Determining the URL from Which to Obtain the API Version Information is an excerpt from the VersionUtil.java sample that demonstrates this general approach. See the getTargetNameSpaceAndVersion method of VersionUtil.java located in the vSphere Web Services SDK package for more information.
Example: Determining the URL from Which to Obtain the API Version Information
try {
String wsdlUrlString = "";
String vimServiceXmlUrlString = "";
 
if((urlString.indexOf("https://") !=-1) || (urlString.indexOf("http://") !=-1)){
wsdlUrlString = urlString.substring(0,urlString.indexOf("/sdk")+4)
    + "/vimService?wsdl";
vimServiceXmlUrlString = urlString.substring(0,urlString.indexOf("/sdk")+4)
    + "/vimServiceVersions.xml";
}
else{
wsdlUrlString = "https://"+ urlString + "/sdk/vimService?wsdl";
vimServiceXmlUrlString = "https://"+ urlString
    + "/sdk/vimServiceVersions.xml";