C# 您能告诉我为什么错误500来自web服务吗
我创建了一个web服务,它采用两个参数 错误详细信息: 远程服务器返回错误:(500)内部服务器错误 文本变量中的消息:C# 您能告诉我为什么错误500来自web服务吗,c#,.net,winforms,web-services,C#,.net,Winforms,Web Services,我创建了一个web服务,它采用两个参数 错误详细信息: 远程服务器返回错误:(500)内部服务器错误 文本变量中的消息: <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><soap:Code><soap:Value>soap:Receiver</soap:Value></soap:Code><soap:Reason><soap:Text xml:lang="en">System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.Xml.XmlException: Data at the root level is invalid. Line 1, position 1.
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.Throw(String res, String arg)
at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace()
at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.XmlTextReader.Read()
at System.Web.Services.Protocols.SoapServerProtocol.SoapEnvelopeReader.Read()
at System.Xml.XmlReader.MoveToContent()
at System.Web.Services.Protocols.SoapServerProtocol.SoapEnvelopeReader.MoveToContent()
at System.Web.Services.Protocols.SoapServerProtocolHelper.GetRequestElement()
at System.Web.Services.Protocols.Soap12ServerProtocolHelper.RouteRequest()
at System.Web.Services.Protocols.SoapServerProtocol.RouteRequest(SoapServerMessage message)
at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)
--- End of inner exception stack trace ---</soap:Text></soap:Reason><soap:Detail /></soap:Fault></soap:Body></soap:Envelope>
soap:ReceiverSystem.Web.Services.Protocols.SoapException:服务器无法处理请求。--System.Xml.XmlException:根级别的数据无效。第1行,位置1。
位于System.Xml.XmlTextReaderImpl.Throw(异常e)
在System.Xml.XmlTextReaderImpl.Throw(String res,String arg)
位于System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace()处
位于System.Xml.XmlTextReaderImpl.ParseDocumentContent()处
位于System.Xml.XmlTextReaderImpl.Read()处
在System.Xml.XmlTextReader.Read()处
在System.Web.Services.Protocols.SoapServerProtocol.SoapEnvelopeReader.Read()中
位于System.Xml.XmlReader.MoveToContent()处
位于System.Web.Services.Protocols.SoapServerProtocol.SoapEnveloperReader.MoveToContent()处
在System.Web.Services.Protocols.SoapServerProtocolHelper.GetRequestElement()中
位于System.Web.Services.Protocols.Soap12ServerProtocolHelper.RouterRequest()中
位于System.Web.Services.Protocols.SoapServerProtocol.RouterRequest(SoapServerMessage消息)
在System.Web.Services.Protocols.SoapServerProtocol.Initialize()中
创建(类型类型、HttpContext上下文、HttpRequest请求、HttpResponse响应、布尔和中止处理)
---内部异常堆栈跟踪的结束---
记录在日志中:根级别的数据无效。没有与xml相关的数据,根级别的数据是什么意思,您能否解释一下,因为它正在浏览器的服务页面中工作。
internal static bool HttpDispatch(string xmlData, string fileName, out string serverMessage)
{
string XMLPath = string.Empty;
try
{
xmlData = "helloXMlData";
string data = string.Format("strXMLData={0}&strXMLFileName={1}", "HELLOxML", "sfr");
byte[] dataStream = Encoding.UTF8.GetBytes(data);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://localhost:64526/myWebService.asmx?op=ReceiveXMLByContent");
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = dataStream.Length;
Stream newStream = request.GetRequestStream();
newStream.Write(dataStream, 0, dataStream.Length);
newStream.Close();
var reader = new System.IO.StreamReader(request.GetResponse().GetResponseStream());
string dataReturn = reader.ReadToEnd();
}
catch (WebException we)
{
//Debugging pourpose
WebResponse errResp = we.Response;
using (Stream respStream = errResp.GetResponseStream())
{
StreamReader reader = new StreamReader(respStream);
string text = reader.ReadToEnd();
}
//End debugging purpose
}
catch (Exception ex)
{
serverMessage = ex.Message;
}
serverMessage = string.Empty;
return false;
}
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><soap:Code><soap:Value>soap:Receiver</soap:Value></soap:Code><soap:Reason><soap:Text xml:lang="en">System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.Xml.XmlException: Data at the root level is invalid. Line 1, position 1.
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.Throw(String res, String arg)
at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace()
at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.XmlTextReader.Read()
at System.Web.Services.Protocols.SoapServerProtocol.SoapEnvelopeReader.Read()
at System.Xml.XmlReader.MoveToContent()
at System.Web.Services.Protocols.SoapServerProtocol.SoapEnvelopeReader.MoveToContent()
at System.Web.Services.Protocols.SoapServerProtocolHelper.GetRequestElement()
at System.Web.Services.Protocols.Soap12ServerProtocolHelper.RouteRequest()
at System.Web.Services.Protocols.SoapServerProtocol.RouteRequest(SoapServerMessage message)
at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)
--- End of inner exception stack trace ---</soap:Text></soap:Reason><soap:Detail /></soap:Fault></soap:Body></soap:Envelope>