通过任务计划程序运行控制台应用程序时无法使用WCF

时间:2016-05-22 17:09:54

标签: vb.net wcf taskscheduler

我有一个简单的控制台应用程序,它使用我创建的WCF服务并在IIS中托管。当我直接运行/调试控制台应用程序时,一切正常。当我通过任务计划程序运行控制台应用程序时,我收到以下错误:

  

22/05/2016 12:46:08 PM - 获取配置文件时出错:http://localhost/ServiceABC没有可以接受该消息的端点。这通常是由错误的地址或SOAP操作引起的。有关更多详细信息,请参阅InnerException(如果存在)。

     

22/05/2016 12:46:08 PM - 内部异常:System.Net.WebException:远程服务器返回错误:(404)Not Found。      在System.Net.HttpWebRequest.GetResponse()      at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)

我的控制台应用程序如下:

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

我的App.config文件如下:

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

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

问题解决了!

我使用了错误的端点地址。我在我的WCF服务中添加了一个netTcpBinding端点,因此控制台应用程序的App.config文件现在包含对以下内容的引用:

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

我将客户端创建为:

Dim client As New WcfServiceLibraryABCIIS.ServiceABCClient("netTcpEndpoint")