views:

956

answers:

4

Is it possible to host custom data on self-hosted HTTP-configured WCF services, such as custom HTML or XML files, without involving IIS? I’m speaking of a ServiceHost instance that instantiates its own EndPoints/listeners.

I have an app that uses a self-hosted WCF service and it has a Windows Forms client but I’m looking at adding a lightweight Silverilght interface as well, but I don’t want to use IIS for the same reason as I didn’t want to use full-blown SQL Server -- I'm trying to make the whole thing self-packaged without IIS dependencies. (Yes, I know that not involving IIS isn’t best practice as it will make it somewhat less reliable and less flexible, but this feature isn’t a major part of this.)

If this is not possible, I’ll have to choose between full-blown IIS on the server or full-blown WPF on the client, I was just curious if anyone had uncovered this before.

Thanks,

Jon

A: 

Have you looked into either System.Net.HttpListener, or even Cassini? Perhaps either of those might provide you with what you need?

Christian Nunciato
A: 

Would hosting the WCF component in a Windows Service be better for your use case?

Terry Donaghe
A: 

OK found my answer. The [OperationContract] has a WebGet property that you can assign a URL. The method this attribute is associated with can then return a Stream object.

Example here: exposing cross-policy file as part of WCF service. :)

With this I can then use Cassini on a separate port to serve Silverlight .xap over HTTP, and still point to the WCF service at the original WCF URL. Theoretically, I could perhaps for that matter even host the .xap and containing HTML from a similar WCF interface, dropping the need for a policy file.

stimpy77
+1  A: 

I have a sample application available for download here that amongst other things demonstrates how to host or stream data from a file to handle (using the WebGet attribute) the client access policy requirements for Silverlight 2 RTM clients connecting to a self-hosted WCF service.

The solution consists of example Silverlight and also WPF client projects and a Console Application project that self-hosts a duplex WCF service and instantiates an instance of a class derived from ServiceHost to expose the appropriate endpoints for the different types of clients.

Perhaps it might be of some help...

Peter McGrattan