WCF mon serveur tcp ne ce lance pas !!!
J'ai besoin de votre aide avec WCF, quand je lance mon application rien ne ce passe mon service wcf qui est en fait un simple serveur tcp ne démarre pas.
Voici le contrat :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| using System;
using System.ServiceModel;
namespace ITCPcontract
{
[ServiceContract(CallbackContract = typeof(IClient))]
public interface IServer
{
[OperationContract]
bool SendMessage ( );
}
[ServiceContract( )]
public interface IClient
{
[OperationContract]
void ReceiveMessage ( string data );
}
} |
Le serveur tcp :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| using System;
using ITCPcontract;
using System.ServiceModel;
namespace SemanticServer
{
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant, InstanceContextMode = InstanceContextMode.PerSession, UseSynchronizationContext = true)]
public class TcpServer : IServer
{
// Client handler
private IClient Client;
/// <summary>
/// Send new Queue to client
/// </summary>
public bool SendMessage ( )
{
bool res = false;
try
{
// Envoie des données
Client = OperationContext.Current.GetCallbackChannel<IClient>( );
Client.ReceiveMessage("Teste");
res = true;
}
catch
{
return false;
}
return res;
}
}
} |
La classe qui me permet de lancer et de fermer le service :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| using System;
using System.ServiceModel;
namespace SemanticServer
{
internal class TcpService
{
internal static ServiceHost myServiceHost = null;
/// <summary>
/// Start wcf service
/// </summary>
internal static void StartService ( )
{
try
{
// ServiceHost
myServiceHost = new ServiceHost(typeof(TcpServer));
//Open myServiceHost
myServiceHost.Open( );
}
catch ( Exception e )
{
Console.WriteLine(e);
}
}
/// <summary>
/// Stop service
/// </summary>
internal static void StopService ( )
{
try
{
//Call StopService from your shutdown logic (i.e. dispose method)
if ( myServiceHost.State != CommunicationState.Closed )
myServiceHost.Close( );
}
catch ( Exception e )
{
Console.WriteLine(e);
}
}
}
} |
Le fichier Program.cs :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| using System;
using System.Diagnostics;
using SemanticServer;
namespace Semantic_System
{
class Program
{
[STAThread]
static void Main ( string[] args )
{
if ( !CheckProcess( ) )
{
TcpService.StartService( );
}
}
/// <summary>
/// Check if the application already running
/// </summary>
private static bool CheckProcess ( )
{
Process pcur = Process.GetCurrentProcess( );
Process[] ps = Process.GetProcesses( );
foreach ( Process p in ps )
{
if ( pcur.Id != p.Id )
{
if ( pcur.ProcessName == p.ProcessName )
{
return true;
}
}
}
return false;
}
}
} |
La définition du service dans App.config
Code:
1 2 3 4 5 6 7 8 9 10 11
| <?xml version="1.0" encoding="utf-8" ?>
<configuration>
<!-- Define WCF service -->
<system.serviceModel>
<services>
<service name="SemanticServer.TcpServer">
<endpoint contract="ITCPcontract.IServer" binding="netTcpBinding" address="net.tcp://82.xxx.xxx.xxx:1303"/>
</service>
</services>
</system.serviceModel>
</configuration> |
L'application ne produit aucune erreur 8O, je ne voie pas du tout ce que j'ai pu oublier de faire
Merci de votre aide