在Windows服务中托管WCF服务

时间:2013-04-26 10:03:56

标签: asp.net wcf windows-services

美好的一天

我想在Windows服务中托管WCF服务,因此我遵循教程:http://msdn.microsoft.com/en-us/library/ff649818.aspx

“步骤8:向客户端添加WCF服务参考”期间,我收到以下错误:

  • 无法连接到net.tcp:// localhost:100 /触发器。
  • 连接尝试的持续时间为00:00:02.0058550。
  • TCP错误代码10061:无法建立连接,因为目标计算机主动拒绝它127.0.0.1:100

我尝试了以下网站上提到的大部分解决方案:http://social.msdn.microsoft.com/forums/en-US/wcf/thread/58e420e9-43a3-4119-b541-d18158038e36/ 没有用。

有人可以对此事发表一些看法吗?

以下是 WCF配置文件

<?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>

接下来是 Windows服务配置文件(根据教程与上面相同):

<?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>

1 个答案:

答案 0 :(得分:0)

感谢evgenyl指出我必须启动Windows服务。 完全错过了这一步。