高分紧急求助,WebService客户端连接错误
服务器端程序:
public XmlDocument DetailYHDPost()
{
//读取流里面的内容
StreamReader sr = new StreamReader(System.Web.HttpContext.Current.Request.InputStream);
string xml = sr.ReadToEnd();
XmlDocument xmldoc = new XmlDocument();
...
...
return xmldoc;
}
客户端程序:
try{
string xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><AAA>bbbb</AAA>"
string url = "http://localhost:8081/DetailPickUP.asmx/DetailYHDPost";
Uri address = new Uri(url);
// Create the web request
HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest;
// Set type to POST
request.Method = "POST";
request.ContentType = "text/xml; charset=utf-8";
request.Headers.Add("x-requested-with","XMLHttpRequest");
// Create a byte array of the data we want to send
byte[] byteData = UTF8Encoding.UTF8.GetBytes(xml);
// Set the content length in the request headers
request.ContentLength = byteData.Length;
// Write data
using (Stream postStream = request.GetRequestStream())
{
postStream.Write(byteData, 0, byteData.Length);
}
string returnData = "";
// Get response
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
// Get the response stream
StreamReader reader = new StreamReader(response.GetResponseStream());
returnData = reader.ReadToEnd();
}
MessageBox.Show(returnData);
}catch (WebException webex)
{
WebResponse errResp = webex.Response;
using (Stream respStream = errResp.GetResponseStream())
{
StreamReader reader = new StreamReader(respStream);
string text = reader.ReadToEnd();
MessageBox.Show(text);
}
}
报了一堆稀奇古怪的错误:
html>
<head>
<title>配置错误</title>
<style>
....
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context)
在 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context)