合约需要 Session,但绑定“WSHttpBinding”不支持它或未正确配置以支持它

问题描述 投票:0回答:1

我已指定服务合同需要会话。

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

服务是这样装饰的:

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

这是我的 App.config 文件:

<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>

当我按 F5 时,我收到错误消息“合同需要会话,但绑定‘WSHttpBinding’不支持它或未正确配置以支持它。”

我真的需要支持SSL并且需要会话的通道。

wcf binding ssl wshttpbinding
1个回答
0
投票

您可以通过启用消息安全来支持会话:

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

如果您需要传输安全,您可能需要指定客户端凭据类型

© www.soinside.com 2019 - 2024. All rights reserved.