Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

914
Views
System.Net.ProtocolViolationException: debe escribir los bytes ContentLength en el flujo de solicitud antes de llamar a [Begin]GetResponse

estoy consiguiendo el

"System.Net.ProtocolViolationException: debe escribir bytes ContentLength en el flujo de solicitud antes de llamar al error [Begin]GetResponse" al llamar al método "BeginGetResponse" de la solicitud web.

Este es mi código:

 try { Stream dataStream = null; WebRequest Webrequest; Webrequest = WebRequest.Create(this.EndPointAddress); Webrequest.Credentials = new NetworkCredential(this.username, this.password); Webrequest.ContentType = "text/xml"; Webrequest.Method = WebRequestMethods.Http.Post; byteArray = System.Text.Encoding.UTF8.GetBytes(xmlRequest.Children[0].InnerXML); Webrequest.ContentLength = byteArray.Length; dataStream = Webrequest.GetRequestStream(); dataStream.Write(byteArray, 0, byteArray.Length); RequestState rs = new RequestState(); rs.Request = Webrequest; IAsyncResult r = (IAsyncResult)Webrequest.BeginGetResponse(new AsyncCallback(RespCallback), rs); } catch (Exception exc) { TRACE.EXCEPTION(exc); } finally { dataStream.Close(); }

Más específicamente, después de llamar a la función "getRequestStream()", el Stream lanza esta excepción por la duración:

'stream.Length' arrojó una excepción de tipo 'System.NotSupportedException'

¿Qué podría estar causándolo?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Esto finalmente funcionó usando:

 using (dataStream = Webrequest.GetRequestStream()) { dataStream.Write(byteArray, 0, byteArray.Length); }

En vez de:

 dataStream = Webrequest.GetRequestStream(); dataStream.Write(byteArray, 0, byteArray.Length);
over 4 years ago · Santiago Trujillo Report

0

Su código debería funcionar para .NET 2.0 Desde 4.0 en adelante, debe cerrar la transmisión después de escribir:

 dataStream = Webrequest.GetRequestStream(); dataStream.Write(byteArray, 0, byteArray.Length); datastream.Close();
over 4 years ago · Santiago Trujillo Report

0

Verifique que su servidor esté configurado para aceptar archivos grandes. Es posible que te encuentres con el límite predeterminado de 4 megas.

Agregue lo siguiente a su archivo web.config para cargar archivos más grandes:

 <system.webServer> <security> <requestFiltering> <requestLimits maxAllowedContentLength="104857600" /> </requestFiltering> </security> </system.webServer>
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!