Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - Unexpected error using WebRequest

Reply
 
Old 05-20-2008   #1 (permalink)
Olivier GIL


 
 

Unexpected error using WebRequest

Hello,

I try to post an HTTP message containing an XML document, and I get the
following exception :

System.Net.WebException: The underlying connection was closed: An unexpected
error occurred on a send. ---> System.IO.IOException: Unable to write data to
the transport connection: Uma solicitação de envio ou recepção de dados não
foi permitida porque o socket não está ligado e (durante o envio num socket
de datagrama utilizando uma chamada sendto) não foi fornecido um endereço.
---> System.Net.Sockets.SocketException: Uma solicitação de envio ou recepção
de dados não foi permitida porque o socket não está ligado e (durante o envio
num socket de datagrama utilizando uma chamada sendto) não foi fornecido um
endereço
at System.Net.Sockets.Socket.Send(Byte[] buffer, Int32 offset, Int32
size, SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset,
Int32 size)
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset,
Int32 size)
at System.Net.PooledStream.Write(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.ConnectStream.WriteHeaders(Boolean async)
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.GetRequestStream()
at Lafon.Easy.Process.DemandesAuSite.ExecuteDemandeSite() in
C:\VSSBASSENS\Easy\Version 2.x\Visual
Studio\Lafon\Easy\Process\genereFich.cs:line 9618

It looks as if the underlying socket was closed prematurely. The problem
occurs on a WINDOWS XP SP2 (Portuguese), but the same code works fine on
other computers with the same operating system.

Framework is version 2.0 SP1. The code is executed from within an ASP.NET
web application running on IIS.

The code is :

string _xmlDemande = "<?xml version=\"1.0\"
encoding=\"iso-8859-\"?><demServ><dem login=\"" + _sLogin + "\" pass=\"" +
_sPass + "\" fich=\"" + _sNomFich + "\" typeRepKo=\"" + sTypeRep + "\"
/></demServ>";

byte[] dataToPost = new ASCIIEncoding().GetBytes(_xmlDemande);

HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("http://" +
_sAdIp + ":" + _sPortHttp + "/demande.xml");
myRequest.Method = "POST";
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.ContentLength = dataToPost.Length;
Stream myStream = myRequest.GetRequestStream();
myStream.Write(dataToPost, 0, dataToPost.Length);
myStream.Close();
WebResponse myResponse = myRequest.GetResponse();
Stream responseStream = myResponse.GetResponseStream();
ReponseSite rep = new ReponseSite();
XmlSerializer serializer = new XmlSerializer(typeof(ReponseSite));
rep = (ReponseSite)serializer.Deserialize(responseStream);
responseStream.Close();
myResponse.Close();
myStream.Close();

Does somebody have any explanation ?

--
Olivier GIL
LAFON SA

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
something unexpected error Live Mail
Unexpected Error: Fax Can't be received because of an unexpected e Vista print fax & scan
unexpected error Vista mail
Net.WebRequest.Create objects GetResponse method returns -1.. why? .NET General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46