public ServiceContent Connect() { if (string.IsNullOrEmpty(this._serviceUrl)) { throw new InvalidOperationException(Resources.InvalidServiceUrl); } try { this._vimService = this.CreateClientChannel(); ServiceContent content = new ServiceInstance((VimClient)this, new ManagedObjectReference() { Type = "ServiceInstance", Value = "ServiceInstance" }).RetrieveServiceContent(); this._version = VersionUtils.GetVIServerVersion(content); this._serviceContent = content; return(this._serviceContent); } catch (ProtocolException ex) { throw new VimProtocolException(ex.Message, (Exception)ex); } catch (EndpointNotFoundException ex) { throw new VimEndpointNotFoundException(ex.Message, (Exception)ex); } catch (SecurityNegotiationException ex) { throw new VimSecurityNegotiationException(ex.Message, (Exception)ex); } catch (CommunicationException ex) { throw new VimException(ex.Message, (Exception)ex); } }
protected virtual void Dispose(bool disposing) { if (disposing) //free managed resources if any { //if (_vimService != null) { _vimService.Dispose(); } } // free native resources if there are any. //_certificateError = null; _serviceContent = null; _serviceUrl = null; _vimService = null; //_serializerCache.Clear(); }
/* private static readonly string VIMSERVICE_VERSIONSXML_URL = "sdk/vimServiceVersions.xml"; * private static readonly string VIMSERVICE_WSDL_URL = "sdk/vimService?wsdl"; * internal static string GetVIServerTNS(string serviceUrl) * { * return "urn:vim25"; * } * internal static Dictionary<string, string> GetVIServerSupportedVersions(string serviceUrl) * { * if (serviceUrl == null) * { * throw new ArgumentNullException(Resources.InvalidServiceUrl); * } * Dictionary<string, string> dictionary = new Dictionary<string, string>(); * Uri uri = new Uri(serviceUrl); * Uri uri2 = new Uri(new Uri(uri.GetLeftPart(UriPartial.Authority)), VersionUtils.VIMSERVICE_VERSIONSXML_URL); * XmlTextReader xmlTextReader = new XmlTextReader(uri2.ToString()); * xmlTextReader.WhitespaceHandling = WhitespaceHandling.None; * try * { * while (xmlTextReader.ReadToFollowing("namespace")) * { * xmlTextReader.ReadStartElement("namespace"); * xmlTextReader.ReadStartElement("name"); * string key = xmlTextReader.ReadString(); * xmlTextReader.ReadEndElement(); * xmlTextReader.ReadStartElement("version"); * string value = xmlTextReader.ReadString(); * xmlTextReader.ReadEndElement(); * dictionary.Add(key, value); * } * xmlTextReader.Close(); * } * catch (WebException) * { * } * return dictionary; * } * internal static VimVersion GetVIServerVersion(string serviceUrl) * { * Dictionary<string, string> vIServerSupportedVersions = VersionUtils.GetVIServerSupportedVersions(serviceUrl); * string vIServerTNS = VersionUtils.GetVIServerTNS(serviceUrl); * VimVersion result; * if (vIServerSupportedVersions.ContainsKey(vIServerTNS)) * { * result = VersionUtils.GetVersionFromApi(vIServerSupportedVersions[vIServerTNS]); * } * else * { * result = VersionUtils.GetVersionFromTNS(vIServerTNS); * } * return result; * } * internal static string GetVimServiceTNS(VimVersion ver) * { * return "urn:vim25"; * } * internal static Type GetVimServiceType(VimVersion ver) * { * return typeof(VimService); * } * internal static Type GetVimType(string typeName, VimVersion ver) * { * Assembly assembly = typeof(VimApi_65.ManagedObjectReference).Assembly; * typeName = "VimApi_65." + typeName; * return assembly.GetType(typeName, false); * } * internal static VimVersion GetVersionFromTNS(string tns) * { * if (tns.Equals("urn:vim25")) * { * return VimVersion.Vim25; * } * if (tns.Equals("urn:vim25")) * { * return VimVersion.Vim4; * } * if (tns.Equals("urn:vim25")) * { * return VimVersion.Vim41; * } * if (tns.Equals("urn:vim25")) * { * return VimVersion.Vim50; * } * if (tns.Equals("urn:vim25")) * { * return VimVersion.Vim51; * } * if (tns.Equals("urn:vim25")) * { * return VimVersion.Vim55; * } * return VimVersion.Vim60; * } */ internal static VimVersion GetVIServerVersion(ServiceContent content) { string apiVersion; if (content != null && content.About != null && content.About.ApiVersion != null) { apiVersion = (content.About.ApiVersion ?? string.Empty); } else { apiVersion = string.Empty; } return(VersionUtils.GetVersionFromApi(apiVersion)); }
public void Disconnect() { this.Logout(); this._vimService = (VimPortType)null; this._serviceContent = (ServiceContent)null; }