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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
[SIZE="4"]/*L'interface et la class service se trouvent dans la même .dll "MyHomeServiceLib.dll"
using System;
using System.ServiceModel;
//L'interface
namespace MyHomeServiceLib
{
[ServiceContract]
public interface IHomeService
{
[OperationContract]
string GetServiceResponse(string question);
}
}
//La classe service
using System;
using System.ServiceModel;
namespace MyHomeServiceLib
{
public class MyHomeService : IHomeService
{
public string GetServiceResponse(String question)
{
//Ici l'implémentation et...
return response;
}
}
}
/*La classe hote du service, une simple application console qui fait référence à la .dll précédente lors de la compilation
using System;
using System.ServiceModel;
using MyHomeServiceLib;
namespace MyServiceHostApp
{
public class MyServiceHost
{
static void Main()
{
try
{
using(ServiceHost host = new ServiceHost(typeof(MyHomeService)))
{
Console.WriteLine("Staring service...");
host.Open(); //Cause de l'exception
Console.ReadLine();
}
}
catch(Exception ex)
{
Console.WriteLine(ex);
}
}
}
}
//Enfin la partie du fichier de configuration concernant le service :
<system.serviceModel>
<services>
<service name="MyHomeServiceLib.MyHomeService">
<endpoint address="http://localhost:8018/MyHomeService"
binding="basicHttpBinding"
contract="MyHomeServiceLib.IHomeService"/>
</service>
</services>
</System.SeviceModel>[/SIZE] |
Partager