当前位置: 代码迷 >> Web Service >> c#webservice中如何把对方传过来的inputstream类型转成string类型
  详细解决方案

c#webservice中如何把对方传过来的inputstream类型转成string类型

热度:235   发布时间:2016-05-02 02:50:41.0
c#webservice中怎么把对方传过来的inputstream类型转成string类型?
对方是传过来的是inputstream类型,我在c#中怎么接受并解析成string类型?

------解决方案--------------------
http://blog.csdn.net/hanqunfeng/article/details/4364583
参考这里
------解决方案--------------------
C# code
[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));      }  }
  相关解决方案