Matt Wilko
Matt Wilko

Reputation: 27322

WCF Basics with a Windows Service

I am looking into WCF specifically in relation to Silverlight.

Can someone tell me if I am correct in thinking that I can create a WCF Service, and expose a TCP endpoint using a Windows Service that my Silverlight app can use?

I have managed to expose this using IIS but it would be good if we could bypass using IIS as some of our customers don't like it.

UPDATE...

OK I have created a WCF Service Library (RemoteClientLib with IRemoteClients defining my service contracts and RemoteClients Implementing this Interface) and a Windows Service to host it. I have added an App.config to both projects that looks like this:

<?xml version="1.0"?>
<configuration>
  <system.serviceModel>
    <services>
      <service name="RemoteClientLib.RemoteClients" behaviorConfiguration="remoteBehavior">
        <endpoint address="" binding="netTcpBinding" contract="RemoteClientLib.IRemoteClients" bindingConfiguration="remoteBinding"/>
        <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://localhost:4520/RemoteClients"/>
          </baseAddresses>
        </host>
      </service>

    </services>
    <bindings>
      <netTcpBinding>
        <binding name="remoteBinding"></binding>
      </netTcpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="remoteBehavior">
          <serviceMetadata/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
  <system.web>
    <compilation debug="true"/>
  </system.web>

  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
</configuration>

I created a project installer to install the service and started it up but when I try and add a service reference in my silverlight project I get 'No connection could be made because the target machine actively refused it' Is there something I am missing?

Upvotes: 0

Views: 750

Answers (3)

kenny
kenny

Reputation: 22334

This sample on codeproject.com I've used for self-hosting WCF services. It would be pretty straight forward to build it into a Windows service. Consider Topshelf as a Windows service framework too.

Upvotes: 1

Matt Klepeis
Matt Klepeis

Reputation: 1722

You can create a windows service that acts as your own host. Here is a link to the various methods available to hosting a WCF service.

Upvotes: 1

tomasr
tomasr

Reputation: 13849

You should be able to do so. Any of the bindings you can use while in IIS, you should be able to use with self-hosting.

Upvotes: 0

Related Questions