使用HttpWebRequest调用wcf一段代码
public class HttpClass { internal static HttpWebRequest _httpWebRequest; public static void Request() { _httpWebRequest = null; _httpWebRequest = (HttpWebRequest)WebRequest.Create("http://wcf.open.cnblogs.com/blog/sitehome/paged/1/2"); _httpWebRequest.Method = "GET"; _httpWebRequest.BeginGetResponse((result) => ResponseCallback(result), _httpWebRequest); } static object _obj = new object(); internal static void ResponseCallback(IAsyncResult result) { HttpWebRequest request = (HttpWebRequest)result.AsyncState; HttpWebResponse httpWebResponse; try { httpWebResponse = (HttpWebResponse)request.EndGetResponse(result); } catch (WebException we) { return; } if (httpWebResponse != null) { lock (_obj) { using (var stream = httpWebResponse.GetResponseStream()) { try { XmlSerializer ser = null; object obj = null; ser = new XmlSerializer(typeof(NewsFeed)); obj = ser.Deserialize(stream); } catch (Exception se) { return; } } } } } }