thebigreddude
thebigreddude

Reputation: 45

No connection could be made because the target machine actively refused using SOAP and REST

I am having problems whenever I am trying to run my client app using SOAP or REST. No matter what, I seem to get rejected on the localhost. I verified I have the correct ports for both services so thought I would post some info here. The error I get is as follows when using my SOAP service:

The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET

I turned on the trace and my REST gets the following

No connection could be made because the target machine actively refused it 127.0.0.1:62928

The web service is defined as such

    public string InsertPatientIDS(PATIENT_IDS patientInfo)
{
    string message;
    SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
    builder.DataSource = "\\SQLExpress";
    builder.InitialCatalog = "pchr42563";
    builder.IntegratedSecurity = true;
    SqlConnection con = new SqlConnection(builder.ConnectionString);

    con.Open();
    SqlCommand cmd = new SqlCommand("INSERT into PATIENT_IDS(PATIENT_ID,LAST_NAME,FIRST_NAME, DATE_OF_BIRTH,ADDRESS_STREET, ADDRESS_STATE, ADDRESS_CITY,ADDRESS_ZIP,PHONE_HOME,PHONE_MOBILE,PRIMARY_ID) values" +
        "(@PATIENT_ID,@LAST_NAME,@FIRST_NAME,@DATE_OF_BIRTH,@ADDRESS_STREET, @ADDRESS_STATE, @ADDRESS_CITY,@ADDRESS_ZIP,@PHONE_HOME,@PHONE_MOBILE,@PRIMARY_ID)",con);
    cmd.Parameters.AddWithValue("@PATIENT_ID", patientInfo.PATIENT_ID);
    cmd.Parameters.AddWithValue("@LAST_NAME", patientInfo.LAST_NAME);
    cmd.Parameters.AddWithValue("@FIRST_NAME", patientInfo.FIRST_NAME);
    cmd.Parameters.AddWithValue("@DATE_OF_BIRTH", patientInfo.DATE_Of_BIRTH);
    cmd.Parameters.AddWithValue("@ADDRESS_STREET", patientInfo.ADDRESS_STREET);
    cmd.Parameters.AddWithValue("@ADDRESS_STATE", patientInfo.ADDRESS_STATE);
    cmd.Parameters.AddWithValue("@ADDRESS_CITY", patientInfo.ADDRESS_CITY);
    cmd.Parameters.AddWithValue("@ADDRESS_ZIP", patientInfo.ADDRESS_ZIP);
    cmd.Parameters.AddWithValue("@PHONE_HOME", patientInfo.PHONE_HOME);
    cmd.Parameters.AddWithValue("@PHONE_MOBILE", patientInfo.PHONE_MOBILE);
    cmd.Parameters.AddWithValue("@PRIMARY_ID", patientInfo.PRIMARY_ID);
    int result = cmd.ExecuteNonQuery();
    if (result == 1)
    {
        message = patientInfo.PRIMARY_ID + " inserted successfully";
    }
    else
    {
        message = patientInfo.PRIMARY_ID + " not inserted successfully";
    }
    con.Close();
    return message; 

and is consumed as such in the client application

ServiceClient client = new ServiceClient();
                PCHRSoapReference1.PATIENT_IDS patientInfo = new PCHRSoapReference1.PATIENT_IDS();
                patientInfo.FIRST_NAME = txtFirst.Text;
                patientInfo.LAST_NAME = txtLast.Text;
                patientInfo.ADDRESS_STREET = txtAddress.Text;
                patientInfo.ADDRESS_CITY = txtCity.Text;
                patientInfo.ADDRESS_STATE = txtState.Text;
                patientInfo.ADDRESS_ZIP = txtZip.Text;
                patientInfo.PHONE_HOME = txtOffice.Text;
                patientInfo.PHONE_MOBILE = txtMobile.Text;
                patientInfo.PRIMARY_ID = txtPrimaryID.Text;
                patientInfo.DATE_Of_BIRTH = dtpDate.Value;
                //give a successful or unsuccessful result
                string result = client.InsertPatientIDS(patientInfo);
                MessageBox.Show(result);

The app.config is also given as

<client>
  <endpoint address="http://localhost:62928/Service.svc" behaviorConfiguration="WebBehavior"
    binding="webHttpBinding" contract="PCHRContracts.IPatientIDS" />
  <endpoint address="http://localhost:59647/Service.svc" binding="wsHttpBinding"
    bindingConfiguration="WSHttpBinding_IService" contract="PCHRSoapReference1.IService"
    name="WSHttpBinding_IService">
    <identity>
      <userPrincipalName value="thebigreddudePC\thebigreddude" />
    </identity>
  </endpoint>
</client>

To make this more readable, I only posted the code for my SOAP service and not the REST because I believe the errors are related to something deeper.

If there is any clear syntax issues than I would appreciate the response. If it is more than likely a local comp issue, then please let me know as well. It has had remote connectivity issues in the past, but this is the first time I have done a localhost. Also, I am not using IIS, just the built in VS one.

Upvotes: 0

Views: 2154

Answers (2)

LB2
LB2

Reputation: 4860

Based on comment discussions, it looks like you are not running your service at the endpoint you specified, http://localhost:62928/Service.svc.

I presume the service is something that you wrote and have source code. Load it in VS and run it. You may need to set project's properties to make sure it always runs using port 62928 and not choose first available. Alternatively, you can configure IIS to point to your project and bind that application to the aforementioned port.

Once you do that, you can quickly test that something is listening by executing in command prompt telnet localhost 62928. If connection is accepted, something is at least listening there. If not, you'll get error message, likely similar to the one you posted.

What's built into VS is a mini web server for hosting web applications (and services), but you need to actually run the project for it to run (or again, use IIS to host, at which point it will be available independently of VS).

Upvotes: 0

Aram Tchekrekjian
Aram Tchekrekjian

Reputation: 935

Most likely, this error means that there might be a firewall blocking your calls. So make sure to turn off the firewall or any anti-malware software on your machine. A similar post further discuss this ... No connection could be made because the target machine actively refused it?

Upvotes: 1

Related Questions