/// <summary> /// Calls the Xeora xService. Default timeout is 60 seconds /// </summary> /// <returns>The result of xService</returns> /// <param name="xServiceUrl">xService Url</param> /// <param name="functionName">Function name</param> /// <param name="parameters">Parameters</param> public static object Call(string xServiceUrl, string functionName, ServiceParameterCollection parameters) => Service.Call(xServiceUrl, functionName, parameters, 60000);
/// <summary> /// Calls the Xeora xService with timeout /// </summary> /// <returns>The result of xService</returns> /// <param name="xServiceUrl">xService Url</param> /// <param name="functionName">Function name</param> /// <param name="parameters">Parameters</param> /// <param name="responseTimeout">Response timeout in milliseconds</param> public static object Call(string xServiceUrl, string functionName, ServiceParameterCollection parameters, int responseTimeout) { Stream requestStream = null; try { requestStream = new MemoryStream( System.Text.Encoding.UTF8.GetBytes( $"xParams={System.Web.HttpUtility.UrlEncode(parameters.ToXml())}" ) ); requestStream.Seek(0, SeekOrigin.Begin); string responseString = null; string pageUrl = $"{xServiceUrl}?call={functionName}"; // Prepare Service Request Connection HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(pageUrl); httpWebRequest.Method = "POST"; httpWebRequest.Timeout = responseTimeout; httpWebRequest.Accept = "*/*"; httpWebRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 5.00; Windows 98)"; httpWebRequest.KeepAlive = false; httpWebRequest.ContentType = "application/x-www-form-urlencoded"; httpWebRequest.ContentLength = requestStream.Length; // !-- // Post ServiceParametersXML to the Web Service byte[] buffer = new byte[512]; int bC; long current = 0; Stream transferStream = httpWebRequest.GetRequestStream(); do { bC = requestStream.Read(buffer, 0, buffer.Length); if (bC <= 0) { continue; } current += bC; transferStream.Write(buffer, 0, bC); OutputTransferProgress?.Invoke(current, requestStream.Length); } while (bC != 0); transferStream.Close(); // !-- HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse(); // Read and Parse Response Datas Stream resStream = httpWebResponse.GetResponseStream(); responseString = string.Empty; current = 0; do { bC = resStream.Read(buffer, 0, buffer.Length); if (bC <= 0) { continue; } current += bC; responseString += System.Text.Encoding.UTF8.GetString(buffer, 0, bC); InputTransferProgress?.Invoke(current, httpWebResponse.ContentLength); } while (bC != 0); httpWebResponse.Close(); return(Service.ParseServiceResult(responseString)); // !-- } catch (Exception ex) { return(new Exception("xService Connection Error!", ex)); } finally { requestStream?.Close(); } }
/// <summary> /// Authenticates to the Xeora xService /// </summary> /// <returns>The result of xService</returns> /// <param name="xServiceUrl">xService Url</param> /// <param name="authenticationFunction">Authentication function</param> /// <param name="parameters">Parameters</param> /// <param name="isAuthenticationDone">If set to <c>true</c> is authentication done</param> public static object Authenticate(string xServiceUrl, string authenticationFunction, ServiceParameterCollection parameters, ref bool isAuthenticationDone) { object methodResult = Service.Call(xServiceUrl, authenticationFunction, parameters); isAuthenticationDone = !(methodResult is Exception); if (!isAuthenticationDone) { return(methodResult); } if (methodResult is Message message && message.Type != Message.Types.Success) { isAuthenticationDone = false; } return(methodResult); }