你能告诉我为什么错误500来自网络服务

时间:2015-08-27 09:31:56

标签: c# .net winforms web-services

我创建了一个带有两个参数的Web服务

enter image description here

POST /myWebService.asmx/ReceiveXMLByContent HTTP/1.1
Host: localhost
Content-Type: application/x-www-form-urlencoded
Content-Length: length

strXMLData=string&strXMLFileName=string

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://myexamplesite.org/myService">string</string>  

这里是http post函数,从winforms c#.net 4.0中调用 它工作但突然间它开始给我错误500

   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;

    }

错误详情:

远程服务器返回错误:(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://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. ---&gt; 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&amp; abortProcessing)
   --- End of inner exception stack trace ---</soap:Text></soap:Reason><soap:Detail /></soap:Fault></soap:Body></soap:Envelope>

0 个答案:

没有答案