Home >Backend Development >C++ >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'?

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'?

Patricia Arquette
Patricia ArquetteOriginal
2025-01-13 09:17:42851browse

Why is My WCF 4.0 File Upload Failing with Error

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:

  • The error occurs at the following line of code: Stream serverStream = request.GetRequestStream();
  • The
  • code attempts to connect to the REST endpoint using HttpWebRequest and HttpWebResponse.

Solution:

The error message indicates that the connection request was rejected by the target computer. Possible reasons:

  • Firewall: Make sure the firewall is turned off or allows connections on the specified port (3446).
  • Host Process: Verify that the WCF service's host process is running and listening on port 3446.

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn