【问题标题】:local WCF client server connection: message that no service is listening本地 WCF 客户端服务器连接:没有服务正在侦听的消息
【发布时间】:2012-01-07 02:57:15
【问题描述】:

两年后,我重新开始实施 WCF 服务。我想让初学者配置一个超级简单的、免费的配置文件服务。我有下面的服务器代码。当我使用 svcutil 创建代理时,一切都很好。但是,当我尝试使用 ChannelFactory 自己实现客户端时,我一直被没有服务正在侦听的消息所困扰......错误在哪里?

客户

Module OnlineLicenceClientConsole

    Sub Main()
        Console.WriteLine("Press enter to connect...")
        Console.ReadLine()
        Dim factory As New ChannelFactory(Of IOnlineLicenceCommunication)(New BasicHttpBinding)
        Dim address As New EndpointAddress("http://localhost:8015/Onlinelicence")
        Dim client = factory.CreateChannel(address)
        Console.WriteLine("Client running...")
        Do While (True)
            Dim computerID = Console.ReadLine()
            Dim request = New LicenceRequest With {.ComputerID = computerID, .CustomerID = "X", .ServiceID = "Y"}
            Console.WriteLine(client.GetLicence(request).StatusMessage)
        Loop
    End Sub

End Module

主人

Module OnlineLicenceServerConsole

    Sub Main()

        Dim baseAddress As New Uri("http://localhost:8015/OnlineLicence")
        Dim host = New ServiceHost(GetType(OnLineLicenceCommunicator), baseAddress)

        Dim serviceBehavior As New ServiceMetadataBehavior With {.HttpGetEnabled = True}
        host.Description.Behaviors.Add(serviceBehavior)

        host.AddServiceEndpoint(
            GetType(IOnlineLicenceCommunication),
            New BasicHttpBinding,
            "OnlineLicenceCommunicator")

        Try
            host.Open()
            Console.WriteLine("Service running")
            Console.ReadLine()
        Catch e As CommunicationException
            Console.WriteLine("Fout: {0}", e.Message)
            Console.ReadLine()
            host.Abort()
        Finally
            host.Close()
        End Try

    End Sub

End Module

【问题讨论】:

    标签: .net wcf wcf-4


    【解决方案1】:

    您传递给ChannelFactory 的构造函数的端点地址不正确。服务基地址为http://localhost:8015/OnlineLicence,而你在host中添加的endpoint相对地址为OnlineLicenceCommunicator,所以endpoint地址为http://localhost:8015/OnlineLicence/OnlineLicenceCommunicator

    Dim factory As New ChannelFactory(Of IOnlineLicenceCommunication)(New BasicHttpBinding) 
    Dim address As New EndpointAddress("http://localhost:8015/Onlinelicence/OnlineLicenceCommunicator") 
    Dim client = factory.CreateChannel(address) 
    

    【讨论】:

    • 一如既往的谦卑、感恩的仆人!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-17
    • 2012-04-08
    • 1970-01-01
    • 1970-01-01
    • 2013-05-18
    • 2010-09-22
    相关资源
    最近更新 更多