Posts in category wcf

WCF inside Windows Service: HTTP could not register URL http://+:8000

Following the  usual-subject kind of MSDN tutorials to make a Windows Service able to communicate with a WPF application (that is have a WCF service hosted inside your Windows Service) I ended with this kind of app.config section:

<services>
      <service name="ConSense.Sensors.Service.ConSenseSensorsWcfService"
               behaviorConfiguration="ConSenseSensorsWcfServiceBehavior">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8000/ConSense/service"/>
          </baseAddresses>
        </host>
        <!-- this endpoint is exposed at the base address provided by host: http://localhost:8000/ConSense/service  -->
        <endpoint address=""
                  binding="wsHttpBinding"
                  contract="ConSense.Sensors.Service.IConSenseSensorsWcfService" />
        <!-- the mex endpoint is explosed at http://localhost:8000/ConSense/service/mex -->
        <endpoint address="mex"
                  binding="mexHttpBinding"
                  contract="IMetadataExchange" />
      </service>
    </services>

In a  UAC environment (Vista/Win7) this leads to the error message shown in the title of this post: HTTP could not register URL http://+:8000 -meaning your LocalService account is not allowed to open such an endpoint.

Maybe due to SOA hype or whatever every tutorial and helpfile around seems to assume you want to build a supercool SOAP Business Service exposed over the internet the moment you set eyes on WCF. This leads to the top 10 Google solutions regarding this exception to suggest you should just run Visual Studio with admin privileges and be done with it. The better answer (at least for my scenario) was to skip the http-stuff and use a named pipe as a WCF endpoint instead:

<services>
      <service name="ConSense.Sensors.Service.ConSenseSensorsWcfService"
               behaviorConfiguration="ConSenseSensorsWcfServiceBehavior">
        <host>
          <baseAddresses>
            <add baseAddress="net.pipe://localhost/ConSenseSensorsService"/>
          </baseAddresses>
        </host>
        <!-- this endpoint is exposed at the base address provided by host: net.pipe://localhost/ConSenseSensorsService  -->
        <endpoint 
                  address="net.pipe://localhost/ConSenseSensorsService"
                  binding="netNamedPipeBinding"
                  bindingConfiguration="netNamedPipeBindingUnsecure"
                  contract="ConSense.Sensors.Service.IConSenseSensorsWcfService" />
        <!-- this mex endpoint is exposed at the base address provided by host: net.pipe://localhost/ConSenseSensorsService/mex -->
        <endpoint address="mex"
                  binding="mexNamedPipeBinding"
                  contract="IMetadataExchange" />
      </service>
    </services>

    <bindings>
      <netNamedPipeBinding>
        <binding name="netNamedPipeBindingUnsecure" >
          <security mode = "None">
          </security>
        </binding >
      </netNamedPipeBinding>
    </bindings>

    <!--For debugging purposes set the 
        includeExceptionDetailInFaults attribute to true-->
    <behaviors>
      <serviceBehaviors>
        <behavior name="ConSenseSensorsWcfServiceBehavior">
          <serviceMetadata />
          <serviceDebug includeExceptionDetailInFaults="True" />
        </behavior>
      </serviceBehaviors>
    </behaviors>