高分紧急求助,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)
...全文
26 点赞 收藏 1
写回复
1 条回复
X_SpringSun 2014年04月28日
怎么会是稀奇古怪。自己静下心好好调试 找下
回复 点赞
发动态
发帖子
C#
创建于2007-09-28

8.5w+

社区成员

64.0w+

社区内容

.NET技术 C#
社区公告
暂无公告