Contract requires Session, but Binding ‘WSHttpBinding’ doesn’t support it or isn’t configured properly to support it

SaneDeveloper picture SaneDeveloper · Oct 27, 2011 · Viewed 10.7k times · Source

I have specified the service contract to require the session.

[ServiceContract(SessionMode = SessionMode.Required)] 
public interface ITicketSales
{
}

The service decorated like this:

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession, ConcurrencyMode = ConcurrencyMode.Single)]
public class TicketSalesService : ITicketSales
{
}

Here is my App.config file:

<system.serviceModel>    
<services>     
  <service name="InternetRailwayTicketSales.TicketSalesImplementations.TicketSalesService" behaviorConfiguration="defaultBehavior">

    <host>
      <baseAddresses>
        <add baseAddress = "https://localhost/TicketSales/"></add>
      </baseAddresses>
    </host>

    <endpoint address="MainService" binding="wsHttpBinding" bindingConfiguration="wsSecureConfiguration"
      contract="InternetRailwayTicketSales.TicketSalesInterface.ITicketSales" />
    <endpoint address="mex" binding="mexHttpsBinding"
      contract="IMetadataExchange"/>
  </service>
</services>

<bindings>
  <wsHttpBinding>
    <binding name="wsSecureConfiguration">
      <security mode="Transport">
        <transport clientCredentialType="None"></transport>
      </security>
    </binding>
  </wsHttpBinding>
</bindings>

<behaviors>
  <serviceBehaviors>
    <behavior name="defaultBehavior">
      <serviceThrottling maxConcurrentInstances="5000" maxConcurrentSessions="5000"/>
      <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="True" />
    </behavior>
  </serviceBehaviors>
</behaviors>

When I press F5 I receive the error message "Contract requires Session, but Binding ‘WSHttpBinding’ doesn’t support it or isn’t configured properly to support it."

I really need the channel which supports SSL and requires session.

Answer

Rob Bowman picture Rob Bowman · Oct 27, 2011

You can support sessions by enabling message security:

<binding name="wsHttpSecureSession">
<security>
<message establishSecurityContext="true"/>
</security>
</binding>

If you need to go with transport security you may need to specify a client credential type