¿Cómo alojar un servicio WCF en un servicio administrado de Windows?
Tengo 3 proyectos en mi solución.
Test Client => para agregar referencias y acceder a través de tcp ipWcfServiceLibruary1 => para ejecutar mis métodos.WindowsService1 => para instalar y ejecutar como servicio de Windows (Cuenta: Servicio de red, Tipo de inicio: Automático)Usé todos los mismos códigos en la muestra msdn
http://msdn.microsoft.com/en-us/library/ff649818.aspx
Utilizo un servicio de wcf que tiene 2 métodos. Quiero usar este servicio de wcf en el servicio administrado de windows. Agregué un servicio de windows a mi solución y establecí referencias.
Uso esta referencia de dirección en mi wcf - app.config:
net.tcp://localhost:2023/Service1
AHORA EL PROBLEMA ES:
Logré agregar referencias a mi proyecto de prueba de cliente usando
net.tcp://localhost:2023/Service1
:
Pero esta dirección de referencia no se usa en la instalación como servicio de Windows. Cuando lo instalo como servicio de Windows, no puedo acceder a esta dirección, Y recibí este error:No connection could be made because the target machine actively refused it
WcfServiceLibruary app.config:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true"/>
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service name="WcfServiceLibrary1.Service1">
<endpoint address="" binding="netTcpBinding" bindingConfiguration="" contract="WcfServiceLibrary1.IService1">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:2023/Service1"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="false"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
Mi servicio de Windows:
protected override void OnStart(string[] args)
{
if (myServiceHost != null)
{
myServiceHost.Close();
}
myServiceHost = new ServiceHost(typeof(Service1));
myServiceHost.Open();
}
Todo funciona bien cuando empiezo en el servicio de visualstudio: