500 internal server error at GetResponse()

后端 未结 8 1852
花落未央
花落未央 2020-12-08 10:37

I have a heavy traffic aspx page calling a web service upon every user`s request as follows.

string uri = \"Path.asmx\";
string soap = \"soap xml string\";

         


        
相关标签:
8条回答
  • 2020-12-08 11:17

    Finally I get rid of internal server error message with the following code. Not sure if there is another way to achieve it.

    
    string uri = "Path.asmx";
    string soap = "soap xml string";
    
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
    request.Headers.Add("SOAPAction", "\"http://xxxxxx"");
    request.ContentType = "text/xml;charset=\"utf-8\"";
    request.Accept = "text/xml";
    request.Method = "POST";
    
    using (Stream stm = request.GetRequestStream())
    {
        using (StreamWriter stmw = new StreamWriter(stm))
        {
            stmw.Write(soap);
        }
    }
    
    using (WebResponse webResponse = request.GetResponse())
    {
    }
    
    
    0 讨论(0)
  • 2020-12-08 11:17

    In my case I just remove the SoapAction instruction from the HttpWebRequest object. So, I don't define .Headers.Add("SOAPAction","someurl") in HttpWebRequest definitions and my code works fine.

    ResultXML is an XDocument. ResultString is a string.

    try
    {
        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(Url);
        //req.Headers.Add("SOAPAction", "http://tempuri.org/IWebService/GetMessage");
        req.ProtocolVersion = HttpVersion.Version11;
        req.ContentType = "text/xml;charset=\"utf-8\"";
        req.Accept = "text/xml";
        req.KeepAlive = true;
        req.Method = "POST";        
    
        using (Stream stm = req.GetRequestStream())
        {
            using (StreamWriter stmw = new StreamWriter(stm))
                stmw.Write(soapStr);
        }
        using (StreamReader responseReader = new StreamReader(req.GetResponse().GetResponseStream()))
        {
            string result = responseReader.ReadToEnd();
            ResultXML = XDocument.Parse(result);
            ResultString = result;      
        }
    }
    
    0 讨论(0)
提交回复
热议问题