public static string GenerateHtml(string queryAddress, string webServiceAddress) { int idx = queryAddress.IndexOf("?"); string windowTabName; if (idx == -1) { windowTabName = queryAddress; } else { windowTabName = queryAddress.Substring(0, idx); } string xsl = GenerateXsl(windowTabName); if (string.IsNullOrEmpty(xsl)) { return(null); } byte[] byteArray = Encoding.UTF8.GetBytes(xsl); MemoryStream streamXslt = new MemoryStream(byteArray); XmlReader xsltReader = XmlReader.Create(streamXslt); XslCompiledTransform xslt = new XslCompiledTransform(); xslt.Load(xsltReader); xsltReader.Close(); streamXslt.Close(); var httpClient = new Feng.Windows.Net.MyAuthHttpClient(); var s = httpClient.GetSync(webServiceAddress + queryAddress); XPathDocument xmlDoc = new XPathDocument(new MemoryStream(Encoding.UTF8.GetBytes(s))); StringWriter sw = new StringWriter(); xslt.Transform(xmlDoc, null, sw); sw.Close(); return(sw.ToString()); //ctx.Response.BufferOutput = true; //ctx.Response.Write(sw.ToString()); //// There is known problem using Response.End(), //// described in Q312629 in the inital release of .Net //// ctx.Response.End() should be used if not for the bug //ctx.ApplicationInstance.CompleteRequest(); }
public static string GenerateHtml(string queryAddress, string webServiceAddress) { int idx = queryAddress.IndexOf("?"); string windowTabName; if (idx == -1) { windowTabName = queryAddress; } else { windowTabName = queryAddress.Substring(0, idx); } string xsl = GenerateXsl(windowTabName); if (string.IsNullOrEmpty(xsl)) { return null; } byte[] byteArray = Encoding.UTF8.GetBytes(xsl); MemoryStream streamXslt = new MemoryStream(byteArray); XmlReader xsltReader = XmlReader.Create(streamXslt); XslCompiledTransform xslt = new XslCompiledTransform(); xslt.Load(xsltReader); xsltReader.Close(); streamXslt.Close(); var httpClient = new Feng.Windows.Net.MyAuthHttpClient(); var s = httpClient.GetSync(webServiceAddress + queryAddress); XPathDocument xmlDoc = new XPathDocument(new MemoryStream(Encoding.UTF8.GetBytes(s))); StringWriter sw = new StringWriter(); xslt.Transform(xmlDoc, null, sw); sw.Close(); return sw.ToString(); //ctx.Response.BufferOutput = true; //ctx.Response.Write(sw.ToString()); //// There is known problem using Response.End(), //// described in Q312629 in the inital release of .Net //// ctx.Response.End() should be used if not for the bug //ctx.ApplicationInstance.CompleteRequest(); }
/// <summary> /// 读入数据 /// </summary> /// <returns>符合条件的数据。结果格式为IList[Dictionary[string, object]]</returns> public System.Collections.IEnumerable GetData(string searchExpression = null, string searchOrder = null, int?firstResult = null, int?maxResult = null) { StringBuilder query = new StringBuilder(); query.Append("?"); if (m_webRestDataFormat == WebRestDatType.Json) { query.Append("format=json&"); } if (!string.IsNullOrEmpty(searchExpression)) { query.Append(string.Format("exp={0}&", searchExpression)); } if (!string.IsNullOrEmpty(searchOrder)) { query.Append(string.Format("order={0}&", searchOrder)); } if (firstResult.HasValue) { query.Append(string.Format("first={0}&", firstResult)); } if (maxResult.HasValue) { query.Append(string.Format("count={0}&", maxResult)); } string addr = m_serviceAddress + query.ToString(); try { var s = m_httpClient.GetSync(addr); if (string.IsNullOrEmpty(s)) { return(null); } string jsonText = null; if (m_webRestDataFormat == WebRestDatType.Json) { jsonText = s; } else if (m_webRestDataFormat == WebRestDatType.Xml) { XmlDocument doc = new XmlDocument(); doc.LoadXml(s); jsonText = Newtonsoft.Json.JsonConvert.SerializeXmlNode(doc); //// XsdDataContractImporter to generate Type from xsd //// Todo: Xsd Validate and Xsd DataType //IList<IDictionary<string, object>> ret = new List<IDictionary<string, object>>(); //if (xmlDoc.HasChildNodes) //{ // foreach (XmlNode node in xmlDoc.ChildNodes) // { // IDictionary<string, object> dict = new Dictionary<string, object>(); // foreach (XmlNode subNode in node.ChildNodes) // { // dict[subNode.Name] = subNode.Value; // // Todo: Change Type // } // ret.Add(dict); // } //} } else { throw new NotSupportedException("Invalid WebRestDatFormat!"); } object data = Newtonsoft.Json.JsonConvert.DeserializeObject(s); var list = data as System.Collections.IEnumerable; if (list == null) { throw new NotSupportedException("Returned Jons string should be IEnumerable!"); } return(list); } catch (Exception ex) { throw new InvalidOperationException("Error when access " + addr, ex); } }