0

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

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

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

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

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>

有什么想法吗?

4

1 回答 1

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")
于 2016-05-22T20:01:27.760 回答