0

After two years I am coming back to implementing a WCF service. I want for starters to configure a super simple, configuration file free service. I have the servercode below. When I use svcutil to create a proxy all is fine. But when I try to implement a client myself using a ChannelFactory I keep being plagued by the message that no service is listening.... Where is the mistake?

The Client

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

The Host

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
4

1 回答 1

3

The endpoint address which you're passing to the constructor of ChannelFactory is incorrect. The service base address is http://localhost:8015/OnlineLicence, and the relative address of the endpoint you added in the host is OnlineLicenceCommunicator, so the endpoint address is 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) 
于 2011-11-27T02:20:03.293 回答