views:

595

answers:

2

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
+2  A: 

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.

Terry Donaghe
Starting the ServiceHost within the WPF Application class seem to fix the issue. Thanks for the book recommendation!
Luke
A: 

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.

Luke