WCF 4.0 file upload failed: Connection refused error (127.0.0.1:3446)
Problem description: When using WCF 4.0 for file upload via streaming, the following error occurs: "The connection cannot be established because the target computer actively rejected it. 127.0.0.1:3446"
Error details:
Stream serverStream = request.GetRequestStream();
HttpWebRequest
and HttpWebResponse
. Solution:
The error message indicates that the connection request was rejected by the target computer. Possible reasons:
Test method:
It is recommended not to test from a Windows Forms project, but to check the connection inside the service itself using the following code:
<code class="language-csharp">string baseAddress = "http://localhost:3446/File/AddStream/stream.txt"; using (HttpClient client = new HttpClient()) { var response = client.GetAsync(baseAddress).Result; if (response.StatusCode == HttpStatusCode.BadRequest) { // 错误处理 } }</code>
Verify using netstat:
To verify that the service is listening on the correct port, use the following command (assuming a Linux system):
<code class="language-bash">netstat -anp | grep 3446</code>
This will output a line indicating whether the service is listening on port 3446. If there is no output, the service is not listening on that port.
The above is the detailed content of Why is My WCF 4.0 File Upload Failing with Error 'No connection could be made because the target machine actively refused it. 127.0.0.1:3446'?. For more information, please follow other related articles on the PHP Chinese website!