高分紧急求助,WebService客户端连接错误

ccccffff 2014-04-28 04:47:57
服务器端程序:
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)
...全文
73 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
X_SpringSun 2014-04-28
  • 打赏
  • 举报
回复
怎么会是稀奇古怪。自己静下心好好调试 找下

110,476

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧