示例#1
0
        /// <summary>
        /// Is Service Valid
        /// </summary>
        /// <returns>True if OK</returns>
        bool ICastRepsitory.IsServiceValid()
        {
            var requestUrl = _CurrentConnection.EndsWith("/") ? _CurrentConnection.Substring(0, _CurrentConnection.Length - 1) : _CurrentConnection;

            requestUrl += "/ping";

            try
            {
                var jsonString = _Client.DownloadString(requestUrl, RequestComplexity.Standard);

                var          serializer = new DataContractJsonSerializer(typeof(string));
                MemoryStream ms         = new MemoryStream(Encoding.Unicode.GetBytes(jsonString));
                try
                {
                    serializer.ReadObject(ms);
                }
                finally
                {
                    ms.Close();
                }
            }
            catch
            {
                return(false);
            }

            return(true);
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="pEntity"></param>
        /// <param name="pComplexity"></param>
        /// <returns></returns>
        private T CallWS <T>(string relativeURL, RequestComplexity pComplexity) where T : class
        {
            var requestUrl = _CurrentConnection.EndsWith("/") ? _CurrentConnection.Substring(0, _CurrentConnection.Length - 1) : _CurrentConnection;

            requestUrl += "/";
            requestUrl += relativeURL.StartsWith("/") ? relativeURL.Substring(1) : relativeURL;

            var jsonString = _Client.DownloadString(requestUrl, pComplexity);

            var          serializer = new DataContractJsonSerializer(typeof(T));
            MemoryStream ms         = new MemoryStream(Encoding.Unicode.GetBytes(jsonString));

            return(serializer.ReadObject(ms) as T);
        }