- 爱易网页
-
XML教程
- 异步伐用xml web service
日期:2014-04-06 浏览次数:20929 次
using System;
using System.Net;
using System.IO;
using System.Text;
using System.Xml;
using System.Collections.Specialized;
using System.Diagnostics;
namespace Technology
...{
/**//// <summary>
/// Summary description for Main.
/// </summary>
class Tester
...{
public void callback(IAsyncResult ar)...{
HttpWebRequest req=(HttpWebRequest)ar.AsyncState;
HttpWebResponse res=(HttpWebResponse)req.EndGetResponse(ar);
Console.WriteLine("*** Response Start ***");
Console.WriteLine(res.StatusCode.ToString());
Console.WriteLine(res.StatusDescription);
//DisplayHeaders
foreach (string sItem in res.Headers)
...{
Console.WriteLine(sItem + ": " + res.Headers[sItem]);
}
Stream stream = res.GetResponseStream();
if (stream != null)
...{
StreamReader sr = new StreamReader(stream, Encoding.ASCII);
Console.WriteLine(sr.ReadToEnd());
}
Console.WriteLine("*** Response End ***");
Console.ReadLine();
}
static void Main(string[] args)
...{
//1.construct request
HttpWebRequest req = (HttpWebRequest )WebRequest.Create("http://localhost/WebService2/Service1.asmx/HelloWorld ");
req.Method = "POST";
req.ContentType="application/x-www-form-urlencoded";
string content="name=100";
req.ContentLength=content.Length;
Stream s = req.GetRequestStream();
StreamWriter sw = new StreamWriter(s);
sw.Write(content);
sw.Close();
Tester t=new Tester();
免责声明: 本文仅代表作者个人观点,与爱易网无关。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。