简体   繁体   中英

Hosting a WCF service in a Windows service

Good day

I want to host a WCF service in a Windows service and as such I am following the tutorial: http://msdn.microsoft.com/en-us/library/ff649818.aspx

During "Step 8: Add a WCF Service Reference to the Client" I get the following errors:

  • Could not connect to net.tcp://localhost:100/Triggers.
  • The connection attempt lasted for a time span of 00:00:02.0058550.
  • TCP error code 10061: No connection could be made because the target machine actively refused it 127.0.0.1:100

I tried most if not all of the solutions mentioned on the following site: http://social.msdn.microsoft.com/forums/en-US/wcf/thread/58e420e9-43a3-4119-b541-d18158038e36/ with no avail.

Can someone please shine some light on this matter please?

Following is the WCF config file :

<?xml version="1.0"?>
<configuration>
<connectionStrings>
<!-- <add name="ABSAConnectionString" connectionString="Data Source=192.168.0.18;Initial Catalog=ABSA;Integrated Security=False;user=Wimpie;password=menschen;" -->
<!-- Charlene -->
<!--<add name="ABSAConnectionString" connectionString="Data Source=ik-charlene\SQL2008;Initial Catalog=ABSA;Integrated Security=True" providerName="System.Data.SqlClient" />-->
<add name="ABSAConnectionString" connectionString="Data Source=.\;Initial Catalog=ABSANICO;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>

<system.web>
<compilation debug="true" targetFramework="4.0" />
<authentication mode="Forms"/>

<authorization>
  <!--<deny users="?"/>-->
  <allow users="?"/>
</authorization>
<membership defaultProvider="Membership">
  <providers>
    <clear/>
    <add name="Membership" type="ABSAService.Membership"/>
  </providers>
</membership>

</system.web>
<system.serviceModel>
<services>
  <service name="ABSAService.Triggers" behaviorConfiguration="ABSAService.TriggersBehavior" >
    <endpoint address="" binding="netTcpBinding" bindingConfiguration="" contract="ABSAService.ITriggers">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="net.tcp://localhost:100/Triggers" />
      </baseAddresses>
    </host>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="ABSAService.TriggersBehavior">
      <serviceMetadata httpGetEnabled="false" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>


<system.diagnostics>
<sources>
  <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
    <listeners>
      <add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData= "c:\log\Traces.svclog" />
    </listeners>
  </source>
  <source name="CardSpace">
    <listeners>
        <add name="xml" />
    </listeners>
  </source>
  <source name="System.IO.Log">
    <listeners>
        <add name="xml" />
    </listeners>
  </source>
  <source name="System.Runtime.Serialization">
    <listeners>
        <add name="xml" />
    </listeners>
  </source>
  <source name="System.IdentityModel">
    <listeners>
        <add name="xml" />
    </listeners>
  </source>
   <source name="UserTraceSource" switchValue="Warning, ActivityTracing" >
      <listeners>
          <add name="xml"
             type="System.Diagnostics.XmlWriterTraceListener"
             initializeData="C:\logs\UserTraces.svclog" />
      </listeners>
   </source>    
</sources>

<trace autoflush="true" /> 

<sharedListeners>
    <add name="xml"
          type="System.Diagnostics.XmlWriterTraceListener"
          initializeData="c:\log\Traces.svclog" />
</sharedListeners>
</system.diagnostics>
</configuration>

Next is the Windows service config file (which is the same as above according to tutorial):

<?xml version="1.0"?>
<configuration>
<connectionStrings>
<!-- <add name="ABSAConnectionString" connectionString="Data Source=192.168.0.18;Initial Catalog=ABSA;Integrated Security=False;user=Wimpie;password=menschen;" -->
<!-- Charlene -->
<!--<add name="ABSAConnectionString" connectionString="Data Source=ik-charlene\SQL2008;Initial Catalog=ABSA;Integrated Security=True" providerName="System.Data.SqlClient" />-->
<add name="ABSAConnectionString" connectionString="Data Source=.\;Initial Catalog=ABSANICO;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>

<system.web>
<compilation debug="true" targetFramework="4.0" />
<authentication mode="Forms"/>

<authorization>
  <!--<deny users="?"/>-->
  <allow users="?"/>
</authorization>
<membership defaultProvider="Membership">
  <providers>
    <clear/>
    <add name="Membership" type="ABSAService.Membership"/>
  </providers>
</membership>

</system.web>
<system.serviceModel>
<services>
  <service name="ABSAService.Triggers" behaviorConfiguration="ABSAService.TriggersBehavior" >
    <endpoint address="" binding="netTcpBinding" bindingConfiguration="" contract="ABSAService.ITriggers">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="net.tcp://localhost:100/Triggers" />
      </baseAddresses>
    </host>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="ABSAService.TriggersBehavior">
      <serviceMetadata httpGetEnabled="false" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
</configuration>

Thanks to evgenyl for pointing out that I had to start the Windows Service. Completely missed this step.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM