///////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Sends an HTTP Request to the backend and parse the response (expected as a BaseEntity object) /// </summary> /// <param name="action">action to query (e.g. "Snippets/Get")</param> /// <param name="data"> /// if the request is a GET, the parameters to be put in the querystring (e.g. "snippetID=100"), /// otherwise data to be put in the post (e.g. "content=...") /// </param> /// <param name="isPost">whether this request is a GET(false) or a POST(true)</param> /// <param name="requiresLogin">false if this request calls a public web service</param> /// <returns>null if any error occurred; the result of the invocation otherwise</returns> protected S2CResBaseEntity <T> SendReqBaseEntity <T>(string action, string data, bool isPost, bool requiresLogin = true) where T : BaseEntity, new() { string response = PrepareAndSendReq(action, data, isPost, requiresLogin); if (string.IsNullOrEmpty(response)) { ErrorCodes errCode = ErrorCodes.COMMUNICATION_ERROR; if (WebConnector.Current.IsTimeout) { errCode = ErrorCodes.TIMEOUT; } SetLastError(log, errCode, S2CRes <string> .GetErrorMsg(errCode)); return(new S2CResBaseEntity <T>(0.0, errCode, null)); } S2CResBaseEntity <T> resp = S2CSerializer.DeserializeBaseEntity <T>(response, m_serialFormat); if (!CheckResp <T>(resp)) { PrintRespError <T>(resp); //if the problem is related to user not logged in, reset login status and retry another time: if (requiresLogin && (resp != null) && (resp.Status == ErrorCodes.NOT_LOGGED_IN)) { WebConnector.Current.ResetLoginStatus(); //reset login status //retry the WS call: response = PrepareAndSendReq(action, data, isPost, requiresLogin); resp = S2CSerializer.DeserializeBaseEntity <T>(response, m_serialFormat); } } return(resp); }