日期:2014-05-17 浏览次数:20831 次
[ServiceContract] public interface IService { [OperationContract] [WebGet] DateTime ServerTime(); } public class Service : IService { public DateTime ServerTime() { return DateTime.Now; } }
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; }
<?xml version="1.0"?> <dateTime xmlns="http://schemas.microsoft.com/2003/10/Serialization/">2012-10-15T18:07:44.8028236+08:00</dateTime>