日期:2014-05-17  浏览次数:20789 次

StreamReader 读取的流
WCF 服务端 是
C# code


    [ServiceContract]
    public interface IService
    {
        [OperationContract]
        [WebGet]
        DateTime ServerTime(); 
    }

     public class Service : IService
    {
        public DateTime ServerTime() { return DateTime.Now; }
    }






C# code

        public string GET(string uri)
        {
            //Web访问对象
            string serviceUrl = string.Format("{0}/{1}", this.BaseUri, uri);
            HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(serviceUrl);

            // 获得接口返回值
            HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
            StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);

            string ReturnXml = reader.ReadToEnd();

            reader.Close();
            myResponse.Close();

            return ReturnXml;
        }



http://localhost:800/Service.svc/ServerTime 得到如下xml结果

C# code


<?xml version="1.0"?>
<dateTime xmlns="http://schemas.microsoft.com/2003/10/Serialization/">2012-10-15T18:07:44.8028236+08:00</dateTime>





ReturnXml 转成字符串后 

是 :

<dateTime xmlns="http://schemas.microsoft.com/2003/10/Serialization/">2012-10-15T18:07:44.8028236+08:00</dateTime>


问题:

我现在想得到时间[color=#FF0000][/color] 

客户端那块怎么处理?



------解决方案--------------------
<dateTime xmlns="http://schemas.microsoft.com/2003/10/Serialization/">2012-10-15T18:07:44.8028236+08:00</dateTime>

的innerText不就是时间吗2012-10-15T18:07:44.8028236+08:00
可以用DateTime.Parse解析。
------解决方案--------------------
这种格式是标准格式,参考:
W3C Date and Time Formats
http://www.w3.org/TR/NOTE-datetime
------解决方案--------------------
探讨

哥们 拟写的那几句 明白

我就是不想找了 麻烦您 写全点 呵呵

写好了 给你分分 哦