Bonjour à tous,

J'ai essayé de mettre en place un service WCF Duplex très simple, en suivant cet exemple.

J'ai donc créé mes deux interfaces :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
using System.ServiceModel;
 
namespace DuplexServeur
{
    [ServiceContract(CallbackContract = typeof(IMyContractCallbak))]
    public interface IServiceHelloWorld
    {
        [OperationContract(IsOneWay = true)]
        void normalFunction();
    }
 
    [ServiceContract]
    public interface IMyContractCallbak
    {
        [OperationContract(IsOneWay = true)]
        void callBackFunction(string str);
    }
 
}

Ainsi que mon service WCF :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
using System.ServiceModel;
 
namespace DuplexServeur
{
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
    public class ServiceHelloWorld : IServiceHelloWorld
    {
        public void normalFunction()
        {
            IMyContractCallbak callback = OperationContext.Current.GetCallbackChannel<IMyContractCallbak>();
            callback.callBackFunction("hello !");
        }
    }
}

J'ai paramétré comme expliqué dans l'article le web.config

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
<?xml version="1.0"?>
<configuration>
 
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
 
    <behaviors>
      <serviceBehaviors>
        <behavior name ="svcbh">
          <serviceMetadata httpGetEnabled="False"/>
          <serviceDebug includeExceptionDetailInFaults="False"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
 
    <services>
 
      <service name="DuplexServer.ServiceHelloWorld" behaviorConfiguration="svcbh">
 
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:9000/ServiceHelloWorld/" />
          </baseAddresses>
        </host>
 
        <endpoint name="duplexendpoint"
                  address=""
                  binding="wsDualHttpBinding"
                  contract="DuplexServer.IServiceHelloWorld" />
 
        <endpoint name="MetaDataTcpEndPoint"
                  address="mex"
                  binding="mexHttpBinding"
                  contract="IMetaDataExchange" />
 
      </service>
 
    </services>
 
 
    </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
 
</configuration>

Puis j'ai voulu testé (en local) dans le navigateur ce qui était généré (le wsdl).

Cependant quand j'ouvre donc l'adresse http://localhost:4528/ServiceHelloWorld.svc

Il y a une erreur :

Server Error in '/' Application.

Le contrat exige le mode Duplex mais la liaison 'BasicHttpBinding' ne le prend pas en charge, ou elle n'est pas configurée correctement pour cela.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Le contrat exige le mode Duplex mais la liaison 'BasicHttpBinding' ne le prend pas en charge, ou elle n'est pas configurée correctement pour cela.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[InvalidOperationException: Le contrat exige le mode Duplex mais la liaison 'BasicHttpBinding' ne le prend pas en charge, ou elle n'est pas configurée correctement pour cela.]
System.ServiceModel.Description.DispatcherBuilder.BuildChannelListener(StuffPerListenUriInfo stuff, ServiceHostBase serviceHost, Uri listenUri, ListenUriMode listenUriMode, Boolean supportContextSession, IChannelListener& result) +12218074
System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription description, ServiceHostBase serviceHost) +1228
System.ServiceModel.ServiceHostBase.InitializeRuntime() +60
System.ServiceModel.ServiceHostBase.OnBeginOpen() +27
System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout) +50
System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +318
System.ServiceModel.Channels.CommunicationObject.Open() +36
System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +184
System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +615

[ServiceActivationException: The service '/ServiceHelloWorld.svc' cannot be activated due to an exception during compilation. The exception message is: Le contrat exige le mode Duplex mais la liaison 'BasicHttpBinding' ne le prend pas en charge, ou elle n'est pas configurée correctement pour cela..]
System.Runtime.AsyncResult.End(IAsyncResult result) +679246
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +190
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.ExecuteSynchronous(HttpApplication context, String routeServiceVirtualPath, Boolean flowContext, Boolean ensureWFService) +234
System.ServiceModel.Activation.HttpModule.ProcessRequest(Object sender, EventArgs e) +355
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +148
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
A partir de là, impossible d'ajouter la référence à ce webservice dans mon application cliente.


Pouvez-vous m'éclairer sur la source de mon erreur ?

Merci à tous.

Cordialement.