public string GetReqContent() { var request = HttpContext.Current.Request; var contentStream = request.InputStream; return new StreamReader(contentStream).ReadToEnd(); }
c#webservice中怎么把对方传过来的inputstream类型转成string类型[WebMethod] public void SendXml() { // 获得客户端RAW HttpRequest var inputStream = HttpContext.Current.Request.InputStream; // 定义Response返回的格式是:Json var response = HttpContext.Current.Response; response.ContentType = "text/json"; //var strXml = ""; //using (var sr = new StreamReader(inputStream)) // strXml = sr.ReadToEnd(); try { DataTable data = new DataTable(); using (var xr = XmlReader.Create(inputStream)) data.ReadXml(xr); // 将读入Xml的DataTable的行数返回客户端 string count = "/"" + data.Rows.Count + "/""; response.BinaryWrite(System.Text.Encoding.UTF8.GetBytes(count)); } catch (Exception ex) { response.BinaryWrite(System.Text.Encoding.UTF8.GetBytes(ex.Message)); } }