/// <summary> /// Devolver informação de conclusão /// </summary> public static void ReturnInfo(HttpContext context, String info) { RespostaInfo resp = new RespostaInfo() { estado = "OK", info = info }; JavaScriptSerializer jss = new JavaScriptSerializer(); string jsonString = jss.Serialize(resp); context.Response.Write(jsonString); AllowCrossDomain(context); }
public static T CallWebService <T>(String url, Dictionary <String, String> parms) { String info; // Obter dados do serviço String json = CallWebService(url, parms); // Tenta converter para o tipo pretendido Exception tipoEx; try { T obj = JSON.FromJSON <T>(json); return(obj); } catch (Exception ex) { // Guardar a excepção tipoEx = ex; } // Se não devolveu o tipo pretendido, verifica se devolveu informação de erro RespostaInfo result = null; try { result = JSON.FromJSON <RespostaInfo>(json); } catch { } if (result != null && result.estado == "ERRO") { info = "Erro a invocar o serviço " + url + "\r\n" + result.info; throw new Exception(result.info); } // Senão, registar mesmo a excepção a converter para o tipo pretendido info = "Erro a invocar o serviço " + url; throw new Exception(info, tipoEx); }