Service WCF dans un service Windows
Hello les amis :D
J'aurais bien besoin d'un petit coup de main sur une appli que je développe.
Je travaille sur un service Windows qui héberge un service WCF afin de pouvoir intéragir avec mon service Windows a partir d'une Api distante.
Premier Windows service et aussi premier WCF service :aie:
J'ai suivis quelques tutos pour en arriver ou j'en suis, plus particulierement ces deux la :
https://docs.microsoft.com/en-us/dot...indows-service
http://dotnetmentors.com/wcf/wcf-res...acontract.aspx
Concernant le service WCF, j'ai créé une interface comme ci-dessous
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
| [ServiceContract]
public interface ISharePointUploaderLocalAgentWCFService
{
[OperationContract]
[WebGet(UriTemplate = "/AgentRunning", ResponseFormat = WebMessageFormat.Json)]
bool AgentRunning();
[OperationContract]
[WebGet(UriTemplate = "/UploadsWatched", ResponseFormat = WebMessageFormat.Json)]
List<SUPUpload> UploadsWatched();
[OperationContract]
[WebInvoke(UriTemplate = "/ModifiyUpload/{UploadId}", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, Method = "PUT")]
SUPUpload ModifiyUpload(SUPUpload Upload, string UploadId);
[OperationContract]
[WebInvoke(UriTemplate = "/AddUpload", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, Method = "POST")]
SUPUpload AddUpload(SUPUpload Upload);
[OperationContract]
[WebInvoke(UriTemplate = "/ModifyTimer/{Secondes}", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, Method = "PUT")]
string ModifyTimer(string Secondes);
[OperationContract]
[WebInvoke(UriTemplate = "/RestartAgent", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, Method = "POST")]
string RestartAgent();
[OperationContract]
[WebInvoke(UriTemplate = "/ScanSourceDirectory", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, Method = "POST")]
string ScanSourceDirectory();
[OperationContract]
[WebInvoke(UriTemplate = "/EnableAgent", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, Method = "PUT")]
string EnableAgent();
[OperationContract]
[WebInvoke(UriTemplate = "/DisableAgent", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, Method = "PUT")]
string DisableAgent();
} |
Et une classe service correspondante
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 48 49 50 51 52 53 54 55 56 57 58 59 60
| [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class SharePointUploaderLocalAgentWCFService : ISharePointUploaderLocalAgentWCFService
{
public SharePointUploaderLocalAgentWCFService(List<SharePointUploaderFileSystemWatcher> watchers)
{
...
}
private List<SharePointUploaderFileSystemWatcher> watchers = null;
public List<SharePointUploaderFileSystemWatcher> Watchers
{
get { return watchers; }
set { watchers = value; }
}
public bool AgentRunning()
{
...
}
public List<SUPUpload> UploadsWatched()
{
...
}
public SUPUpload ModifiyUpload(SUPUpload Upload, string UploadId)
{
...
}
public SUPUpload AddUpload(SUPUpload Upload)
{
...
}
public string ModifyTimer(string Secondes)
{
...
}
public string RestartAgent()
{
...
}
public string ScanSourceDirectory()
{
...
}
public string EnableAgent()
{
...
}
public string DisableAgent()
{
...
} |
J'ai mis a jour mon fichier AppConfig avec le code suivant
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
| <system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<services>
<service behaviorConfiguration="Default" name="SharePointUploaderLocalAgent.Services.SharePointUploaderLocalAgentWCFService">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000"/>
</baseAddresses>
</host>
<endpoint address="" behaviorConfiguration="webBehavior" binding="webHttpBinding" contract="SharePointUploaderLocalAgent.Services.ISharePointUploaderLocalAgentWCFService" />
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="webBehavior">
<webHttp helpEnabled="true" />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="Default">
<serviceMetadata httpGetEnabled="true" />
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel> |
NB: Un tuto utilise le port 8000, l'autre le port 61090. J'ai essayé avec les deux, sans succés.
J'ai testé mon service Windows en application console, il tourne correctement, le service WCF est bien ouvert comme suit et conservé dans une variable de mon service Windows
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| protected override void OnStart(string[] args)
{
try
{
...
// Create a ServiceHost for the SharePointUploaderLocalAgentWCFService type
serviceHost = new ServiceHost(new SharePointUploaderLocalAgentWCFService(watchers));
serviceHost.Open();
}
catch(Exception ex)
{
Notifier myNotifier = new Notifier();
myNotifier.NotifyError(new Exception("An unexpected error occured while starting the service. ", ex));
Stop();
}
} |
J'ai donc installé mon service Windows, lancé le service, j'ai attaché le debugger au service, mais quand je tape l'adresse http://localhost:8000/UploadsWatched par exemple, mon point d'arret n'est pas atteint, et le browser ne peut pas afficher la page.
Tout d'abord, concernant le fait que je n'atteigne pas mon service en local, j'aurais pensé a un problememe de réglage dans le fichier AppConfig. J'ai cherché mais je ne vois pas ce qui cloche. Si quelqu'un peut m'ouvrir les yeux, much appreciated :oops:
Ensuite, j'ai du mal a voir comment mon Api pourrait accéder a mon service WCF sans qu'il ne soit déployé dans IIS. Quelqu'un pourrait-il m'éclaircir sur le sujet please? Des explications, un tuto peut-etre? :calim2:
Merci d'avance pour votre aide!
PS : désolé pour les accents ou autres, clavier QWERTY, Scotland oblige :mrgreen: