1
I’m using this code below to send a xml to the webservice from city hall, the maximum RPS you send is 40. What happens is that I already sent with 40 and did not get problems earlier.
It is generated only once a month, when I Gero for example, I am trying to generate with 13 RPS, it returns me a generic error: 
An error occurred while sending the request. ; The server returned an invalid or unrecognized Response.
So I can not know where the problem is, I thought it could be in the code, but with 1 RPS per batch sent correctly, and with 5 also.
 private string postB(string url, string method, string xml, string numero, int idempresa, string ws)
    {
        try
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(xml);
            HttpWebRequest webRequest = getWebRequestB(url, method);
            webRequest.Timeout = Timeout.Infinite;
            //webRequest.KeepAlive = true;
            webRequest.Proxy = HttpWebRequest.GetSystemWebProxy();
            webRequest.UseDefaultCredentials = true;
            webRequest.Proxy.Credentials = CredentialCache.DefaultCredentials;
            WebProxy myProxy = new WebProxy();
            Uri myUri = new Uri("http://192.168.0.3:3128");
            myProxy.Address = myUri;
            myProxy.Credentials = CredentialCache.DefaultCredentials;
            webRequest.Proxy = myProxy;
            montaEnvelopeB(webRequest, doc, numero, xml, idempresa, ws);
            return getSoapResponseB(webRequest);
        }
        catch (WebException webex)
        {
            WebResponse errResp = webex.Response;
            if (errResp != null)
            {
                using (Stream respStream = errResp.GetResponseStream())
                {
                    StreamReader reader = new StreamReader(respStream);
                    msgm = reader.ReadToEnd();
                    cod = "Erro";
                }
            }
            else { cod = "Erro";  msgm = webex.ToString(); }
            return msgm;
        }
    }
I’ve tried to put with webRequest.KeepAlive = true; but did not give, nor putting with false.
The message states that the request did not result in a successful status, but it may be bringing a description of the error. It’s probably a 400 (Bad request) because you’re not delivering the xml in the envelope the service is waiting for
– Leandro Angelo
@Leandroangelo then the xml is generated in the same way, with the same treatment, when I send several it returns this error, when I send less goes, I even thought it could be something that was not treated, some character in particular or something of the type, but when generating one by one, or 5 for example, it worked.
– Mariana
in this scenario makes sense to be some character or one of the items that is breaking your lot even
– Leandro Angelo