0

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.

  • It looks like connection cannot be made to `127.0.0.1:62928`. Check your firewall to make sure it is not blocking. Check to make sure there is indeed something listening there (`netstat -a -o`). – LB2 May 13 '14 at 20:24
  • Well I'll be. I don't have anything listening on either of the ports I specified. I'm not sure how to approach that. I have no virus or firewall enabled, in fact I took the extra step to remove them. I have no idea why they are not working though. – thebigreddude May 13 '14 at 20:39
  • well, your service handler has to be listening on those ports, since that's what is configured and your code is making a call. Have you started those services (be it from IDE, IIS, or whatever is suppose to provide them)? – LB2 May 13 '14 at 20:42
  • I might be naive in thinking this, but I thought I was using one built into the visual studio software? When I went through the Microsoft Visual C# 2010 Step by Step book, it did not mention starting anything separate. I know just enough to know it was not using IIS – thebigreddude May 13 '14 at 20:49
  • To clarify, this is exception that you receive in your client code, not inside your webservice, right? – LB2 May 13 '14 at 20:53
  • Correct, only from the client. – thebigreddude May 13 '14 at 20:55

2 Answers2

1

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?

Community
  • 1
  • 1
Aram Tchekrekjian
  • 925
  • 11
  • 26
0

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).

LB2
  • 4,802
  • 19
  • 35
  • Yes I am getting an error 400 from telnet which is to be expected. I guess I might be confused bc I can pull up the localhost:62928/Service.svc but I cannot access it from my app. Does that matter at all, or is that misleading? Unfortunately I used Microsoft VS express for web to create the web service and there are no options for setting configuring a fixed port I found out. I had not touched IIS because it was outside of the text books but I only have a few hours to finish debugging. – thebigreddude May 13 '14 at 21:24
  • If you're able to connect via telnet (and firewall not interfering), then your app should be able to connect as well... I'm not sure at this point why telnet would work, but your app wouldn't... – LB2 May 13 '14 at 21:36
  • Based on all of this I am almost sure I have my endpoints messed up somehow. But to be clear I can go to the localhost in a browser and it pulls up but telnet gets an error 400 for a bad request. – thebigreddude May 13 '14 at 21:41
  • Right, telnet doesn't get properly formatted request, and thus gives back `400`, whereas browser sends good http request. All I can say is that while you see browser getting good responses from the service, try your app again. perhaps svc was off when you tried last, and is working now? – LB2 May 13 '14 at 21:48
  • No unfortunately I keep trying but it keeps doing the same thing. I have recompiled the both the client and webclient but still not getting anywhere. I have been suspicious of my computer for quite some time ever since I was the only person in our household with a computer that could not attach to our xbox to stream media. It would time out constantly. Not sure if they are related and I gave up on that a year back. – thebigreddude May 13 '14 at 22:12