Ho un servizio WCF con wsHttpBindings e SSL abilitato, ma mi piacerebbe abilitare le sessioni WCF.Come abilitare la sessione con SSL wsHttpBinding in WCF
Dopo aver cambiato SessionMode a richiesta
SessionMode:=SessionMode.Required
sto ottenendo l'errore descritto di seguito.
Il contratto richiede Session, ma Binding 'WSHttpBinding' non supporta o non è configurato correttamente per supportarlo.
Ecco la mia applicazione di esempio.
App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<client />
<bindings>
<wsHttpBinding>
<binding name="NewBinding0" useDefaultWebProxy="false" allowCookies="true">
<readerQuotas maxStringContentLength="10240" />
<!--reliableSession enabled="true" /-->
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None" >
<extendedProtectionPolicy policyEnforcement="Never" />
</transport >
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service name="WcfServiceLib.TestService">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="NewBinding0"
contract="WcfServiceLib.ITestService">
<identity>
<servicePrincipalName value="Local Network" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="https://test/TestService.svc" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information,
set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpsGetEnabled="True"/>
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
ITestService.vb
<ServiceContract(SessionMode:=SessionMode.Required)>
Public Interface ITestService
<OperationContract(IsInitiating:=True, IsTerminating:=False)> _
Function GetData(ByVal value As Integer) As String
End Interface
TestService.vb
<ServiceBehavior(InstanceContextMode:=InstanceContextMode.PerSession, _
ReleaseServiceInstanceOnTransactionComplete:=False, _
ConcurrencyMode:=ConcurrencyMode.Single)>
Public Class TestService
Implements ITestService
Private _user As User
<OperationBehavior(TransactionScopeRequired:=True)>
Public Function GetData(ByVal value As Integer) As String _
Implements ITestService.GetData
If _user Is Nothing Then
_user = New User()
_user.userName = "User_" & value
_user.userPassword = "Pass_" & value
Return String.Format("You've entered: {0} , Username = {1} , Password = {2} ", _
value, _user.userName, _user.userPassword)
Else
Return String.Format("Username = {1} , Password = {2} ", _
_user.userName, _user.userPassword)
End If
End Function
End Class
Ho provato tutte Po soluzioni ssible, ho potuto trovare, ma nulla ha aiutato.
Alcuni consigli per consentire sessioni affidabili, ma non funziona con SSL (se solo si dispone vincolante vostra abitudine), gli altri consigli per utilizzare http invece di https, ma mi piacerebbe come abilitare Sessioni con le mie attuali configurazioni, se è possibile.
C'è qualche approccio per raggiungere questo obiettivo?
Qualsiasi tipo di aiuto è molto apprezzato.
Qual è la ragione per abilitare lo stato di sessione sul servizio wcf? Questo potrebbe essere un collo di bottiglia se stai cercando prestazioni elevate. Dovrebbe essere evitato il servizio wcf di sessione. –
Mi piacerebbe avere una variabile _user per ogni sessione. Ricevo una nuova istanza di classe di servizio per ogni chiamata. il valore di _user è sempre Nothing. – hgulyan
Quale soluzione dovrei usare per la mia situazione, se devo memorizzare i dati per ogni cliente? – hgulyan