Luke
Luke

Reputation: 6315

WCF Named Pipes within WPF application

How would you run a WCF named pipe service in the background of a WPF Windows application? I can't seem to find any samples of running the WCF server within a WPF application.

Any ideas?

I am currently using the following code in the Application_Startup. Does this need to run with it's own thread?

    Using Host As ServiceModel.ServiceHost = New ServiceModel.ServiceHost(GetType(Service), New Uri(("net.pipe://localhost")))
        '
        Host.AddServiceEndpoint(GetType(IService), New ServiceModel.NetNamedPipeBinding, "Test")
        Host.Open()
        '
    End Using

Upvotes: 3

Views: 2048

Answers (2)

Luke
Luke

Reputation: 6315

I removed the Using code block and setup the ServiceHost as a private variable within the WPF Application class. I then close the ServiceHost when the application exits. Seems to work fine.

Upvotes: 0

Tad Donaghe
Tad Donaghe

Reputation: 6588

Juval Lowy provides helper classes in his ServiceModelEx library along with information on how to run WCF components in-process, which is probably what you're going to want to do with your WCF component since you want to use named-pipes which requires the component to be running on the same machine as your WPF app.

I suggest reading about the InProcFactory class starting on page 60 of the 2nd Edition of "Programming WCF Services" by Juval Lowy. This is essentially the "bible" of WCF.

This will show you exactly how to host your component in process using his helper classes.

Upvotes: 2

Related Questions