0

I have a simple console app that consumes a WCF service I created and am hosting in IIS. When I run/debug the console app directly, everything works fine. When I run the console app through Task Scheduler, I get the following error:

22/05/2016 12:46:08 PM - Error getting profiles: There was no endpoint listening at http://localhost/ServiceABC that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.

22/05/2016 12:46:08 PM - Inner Exception: System.Net.WebException: The remote server returned an error: (404) Not Found. at System.Net.HttpWebRequest.GetResponse() at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)

My console app is as follows:

Sub Main()
    GetProfiles()
End Sub

Sub GetProfiles()
    Try
        WriteToFile("Getting Profiles")
        Dim client As New WcfServiceLibraryABCIIS.ServiceABCClient
        client.Endpoint.Binding.SendTimeout = New TimeSpan(0, 20, 0)
        client.GetProfiles()
        WriteToFile("Finished Getting Profiles")
    Catch ex As Exception
        'WriteToFile("Error getting profiles: " + ex.Message + ex.StackTrace)
        WriteToFile("Error getting profiles: " + ex.Message)
        WriteToFile("Inner Exception: " + ex.InnerException.ToString)
    End Try

End Sub

Private Sub WriteToFile(text As String)
    text = DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt") + " - " + text
    Dim path As String = "C:\Users\abcuser\Documents\ServiceLog.txt"
    Using writer As New StreamWriter(path, True)
        writer.WriteLine(String.Format(text, DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt")))
        writer.Close()
    End Using
End Sub

My App.config file is as follows:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
    </startup>
    <system.serviceModel>
        <bindings>
            <wsHttpBinding>
                <binding name="WSHttpBinding_IServiceABC" />
            </wsHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost/ServiceABC" binding="wsHttpBinding"
                bindingConfiguration="WSHttpBinding_IServiceABC" contract="WcfServiceLibraryABCIIS.IServiceABC"
                name="WSHttpBinding_IServiceABC">
                <identity>
                    <userPrincipalName value="ABCCOMPUTER\abcuser" />
                </identity>

            </endpoint>
        </client>
     </system.serviceModel>
</configuration>

Any thoughts?

rkm2
  • 53
  • 1
  • 8

1 Answers1

0

Problem solved!

I was using the wrong endpoint address. I added a netTcpBinding endpoint to my WCF Service, so the console app's App.config file now includes a reference to:

<endpoint address="net.tcp://localhost/ServiceABC" binding="netTcpBinding"
            bindingConfiguration="netTcpEndpoint" contract="WcfServiceLibraryABCIIS.IServiceABC"
            name="netTcpEndpoint">

And I create the client as:

Dim client As New WcfServiceLibraryABCIIS.ServiceABCClient("netTcpEndpoint")
rkm2
  • 53
  • 1
  • 8