/// <summary> /// Create a WSConnector for the given service and function. /// </summary> /// <param name="credentials">The credentials for the service.</param> /// <param name="function">The name of the function to connect.</param> /// <param name="args">Additional function arguments.</param> /// <returns>The WSConnector object or null or error.</returns> public static WSConnector CreateConnector(Credentials credentials, string function, string args) { WSConnector connector = new WSConnector(); if (credentials.HasCredentials()) { connector.Authentication = credentials; } else if (credentials.HasIamTokenData()) { credentials.GetToken(); connector.Headers.Add(AUTHENTICATION_AUTHORIZATION_HEADER, string.Format("Bearer {0}", credentials.IamAccessToken)); } connector.URL = FixupURL(credentials.Url) + function + args; return(connector); }
/// <summary> /// Create a WSConnector for the given service and function. /// </summary> /// <param name="authenticator">The authenticator for the service.</param> /// <param name="function">The name of the function to connect.</param> /// <param name="args">Additional function arguments.</param> /// <param name="serviceUrl">Service Url to connect to.</param> /// <returns>The WSConnector object or null or error.</returns> public static WSConnector CreateConnector(Authenticator authenticator, string function, string args, string serviceUrl) { if (string.IsNullOrEmpty(serviceUrl)) { throw new ArgumentNullException("The serviceUrl must not be empty or null."); } if (Utility.HasBadFirstOrLastCharacter(serviceUrl)) { throw new ArgumentException("The serviceUrl property is invalid. Please remove any surrounding {{, }}, or \" characters."); } WSConnector connector = new WSConnector(); connector.Authentication = authenticator; connector.URL = FixupURL(serviceUrl) + function + args; authenticator.Authenticate(connector); return(connector); }