Getting an error: Contract requires Duplex, but Binding 'BasicHttpBinding' doesn't support it or isn't configured properly to support it

14,110

If that is the extent of your web.config configuration for WCF, then you are missing the section that defines your contract:

<services>
  <service name="WebApplication1.Service1">
    <endpoint address="" binding="wsDualHttpBinding" contract="WebApplication1.IService1" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>
</services>

If you do have this section specified, the other likely cause is that the contract name is not fully qualified; it must include the full namespace and not just the name of the contract.

Here is the full System.ServiceModel configuration:

  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    <services>
      <service name="WebApplication1.Service1">
        <endpoint address="" binding="wsHttpBinding" contract="WebApplication1.IService1" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
  </system.serviceModel>

In this case, the application namespace is WebApplication1, the service's class name is Service1 (i.e. Service1.svc) and the interface that Service1 implements is IService1.

Share:
14,110
assafmo
Author by

assafmo

Updated on June 05, 2022

Comments

  • assafmo
    assafmo almost 2 years

    I have a WCF service and a Silverlight 5 client. I've defined the following interfaces:

    [ServiceContract(Namespace = "Silverlight", CallbackContract = typeof(IDuplexClient))]
    public interface IDuplexService
    {
        [OperationContract]
        void Subscribe(string userId);
    
        [OperationContract]
        void Unsubscribe(string userId);
    }
    
    [ServiceContract]
    public interface IDuplexClient
    {
        [OperationContract(IsOneWay = true)]
        void PushNotification(string msg);
    }
    

    And this is my Web.config file:

    <configuration>
      <system.serviceModel>
        <behaviors>
          <serviceBehaviors>
            <behavior name="">
              <serviceMetadata httpGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="false" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
      </system.serviceModel>
    </configuration>
    

    When I try to run the service I get:

    The service '/ServerService.svc' cannot be activated due to an exception during compilation. The exception message is: Contract requires Duplex, but Binding 'BasicHttpBinding' doesn't support it or isn't configured properly to support it.

    I know I need to add some properties to Web.config, but wherever I looked (and whatever I tried) I couldn't make it work.

    I'm new to WCF and I'd like your help on that subject. All my googling lead me nowhere and the answers people who asked here the same question got doesn't work for me.

    So I've decided to give up searching and just ask.

    Update: I used this link to create the interface - http://msdn.microsoft.com/en-us/library/cc645027%28v=vs.95%29.aspx

  • assafmo
    assafmo over 11 years
    Can you please explain what are MyService,MySLServiceBehavior,MySLService,IMyService and IMetadataExchange? This is not that obvious in the eyes of a beginner. Also don't I need to add some <binding> property?
  • competent_tech
    competent_tech over 11 years
    Cleaned up the answer slightly to make it more understandable and added the full config.
  • assafmo
    assafmo over 11 years
    Thank you, but I still don't see the full config.
  • competent_tech
    competent_tech over 11 years
    Sorry, forgot to indent it. It is there now.
  • assafmo
    assafmo over 11 years
    Changed wsHttpBinding to wsDualHttpBinding and no error! Thank you! :-)
  • competent_tech
    competent_tech over 11 years
    Excellent news! I have updated the answer in case someone else runs into this down the road.