none
Stream.Write Error RRS feed

  • 問題

  • 我有一段程式,將soap封包透過http協定送至另一台server,部分code如下

    ps.soapMsg是soap封包字串,soapurl是server url字串 

    ASCIIEncoding encoding = new ASCIIEncoding();
       byte[] byte1 = encoding.GetBytes(soapMsg);

       WebRequest wr = WebRequest.Create(soapurl);
       wr.Headers.Add("SoapAction",soapurl);
       wr.ContentType = "text/xml;Charset=\"utf-8\"";
       wr.ContentLength = soapMsg.Length;
       wr.Method = "POST";
       Stream stm = wr.GetRequestStream();
       stm.Write(byte1,0,byte1.Length);

       WebResponse resp = wr.GetResponse();
       stm = resp.GetResponseStream();
    但在執行時,出現了"連線已被您主機上的軟體中止。 "的錯誤訊息,

    停在stm.Write(byte1,0,byte1.Length);

    stack trace如下

    [SocketException (0x2745): 連線已被您主機上的軟體中止。]
       System.Net.Sockets.Socket.BeginSend(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags, AsyncCallback callback, Object state) +442
       System.Net.Sockets.NetworkStream.BeginWrite(Byte[] buffer, Int32 offset, Int32 size, AsyncCallback callback, Object state) +108

    [IOException: 無法寫入資料至傳輸連接。]
       System.Net.Sockets.NetworkStream.BeginWrite(Byte[] buffer, Int32 offset, Int32 size, AsyncCallback callback, Object state) +156
       System.Net.Connection.BeginWrite(Byte[] buffer, Int32 offset, Int32 size, AsyncCallback callback, Object state) +108
       System.Net.ConnectStream.BeginWrite(Byte[] buffer, Int32 offset, Int32 size, AsyncCallback callback, Object state) +1187
       System.Net.ConnectStream.Write(Byte[] buffer, Int32 offset, Int32 size) +33
       HNCBGateway._Default.SendSOAPEnvelope1(String soapMsg) in c:\inetpub\wwwroot\hncbgateway\default.aspx.cs:181
       HNCBGateway._Default.btnPing_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\hncbgateway\default.aspx.cs:164
       System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
       System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
       System.Web.UI.Page.ProcessRequestMain() +1292

    有哪位高手可以指導一下,已經被這問題煩惱很久了,謝謝


    2006年3月15日 上午 11:54

解答

所有回覆