Tajuk ditulis semula sebagai: Sambungan ke 127.0.0.1:3446 telah ditolak secara aktif oleh mesin sasaran
<p>Saya menggunakan templat WCF4.0 -REST. Saya cuba mencipta kaedah untuk memuat naik fail menggunakan aliran.</p>
<p>问题总是发生在</p>
<pre class="brush:php;toolbar:false;">Stream serverStream = request.GetRequestStream();</pre>
<p>流式传输类:</p>
<pre class="brush:php;toolbar:false;">ruang nama LogicClass
{
kelas awam StreamClass : IStreamClass
{
public bool UploadFile(nama fail rentetan, Aliran fail Strim)
{
cubalah
{
FileStream fileToupload = new FileStream(nama fail, FileMode.Create);
byte[] bytearray = new byte[10000];
int bytesRead, totalBytesRead = 0;
buat
{
bytesRead = fileStream.Read(bytearray, 0, bytearray.Length);
totalBytesRead += bytesRead;
} manakala (baitBaca > 0);
fileToupload.Write(bytearray, 0, bytearray.Length);
fileToupload.Close();
fileToupload.Dispose();
}
tangkap (Exception ex) { throw new Exception(ex.Message); }
kembali benar;
}
}
}</pre>
<p>REHAT 项目:</p>
<pre class="brush:php;toolbar:false;">[WebInvoke(UriTemplate = "AddStream/{filename}", Method = "POST", BodyStyle = WebMessageBodyStyle.Bare)]
public bool AddStream(nama fail rentetan, System.IO.Stream fileStream)
{
LogicClass.FileComponent rest = LogicClass.FileComponent();
return rest.AddStream(nama fail, fileStream);
}</pre>
<p>Windows 窗体项目:用于测试</p>
<pre class="brush:php;toolbar:false;">private void button24_Click(objek penghantar, EventArgs e)
{
byte[] fileStream;
menggunakan (FileStream fs = new FileStream("E:stream.txt", FileMode.Open, FileAccess.Read, FileShare.Read))
{
FileStream = bait baharu[fs.Length];
fs.Read(fileStream, 0, (int)fs.Length);
fs.Close();
fs.Buang();
}
string baseAddress = "http://localhost:3446/File/AddStream/stream.txt";
Permintaan HttpWebRequest = (HttpWebRequest)HttpWebRequest.Create(baseAddress);
request.Method = "POST";
request.ContentType = "teks/plain";
Stream serverStream = request.GetRequestStream();
serverStream.Write(fileStream, 0, fileStream.Length);
serverStream.Close();
menggunakan (HttpWebResponse response = request.GetResponse() sebagai HttpWebResponse)
{
int statusCode = (int)response.StatusCode;
Pembaca StreamReader = StreamReader baharu(response.GetResponseStream());
}
}</pre>
<p>我已关闭防火墙和 Internet 连接,但错误仍然存在。Adakah terdapat cara yang lebih baik untuk menguji kaedah muat naik? </p>
<p>Jejak tindanan: </p>
<blockquote>
<p>Di System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, alamat soket SocketAddress)
di System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception)</p>
</blockquote><p><br /></p>