2011-10-16 18 views
6

Ho bisogno di abilitare le sessioni nel mio servizio WCF. Quindi devo:WCF aspNetCompatibilityEnabled = "true" genera un'eccezione (impossibile caricare)

<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/> 

Quando faccio che ottengo un'eccezione:

Il servizio non può essere attivato perché non supporta ASP.NET compatibilità. La compatibilità ASP.NET è abilitata per questa applicazione. Disattivare la modalità di compatibilità ASP.NET nel web.config o aggiungere l'attributo AspNetCompatibilityRequirements al tipo di servizio con impostazione RequirementsMode come 'ammessi' o 'required'

Questo è il mio web.config:

<compilation debug="true"> 
    <assemblies> 
    <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/> 
    <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
    </assemblies> 
</compilation> 

<services> 
    <service behaviorConfiguration="ExecutionEngine.AccountsBehavior" name="WebService.Services.Accounts"> 
    <endpoint address="" binding="wsHttpBinding" contract="WebService.Services.IAccounts" bindingConfiguration="SafeServiceConf"> 
     <identity> 
     <dns value="localhost"/> 
     </identity> 
    </endpoint> 
    <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/> 
    </service> 
</services> 



<behaviors> 
    <serviceBehaviors> 
    <behavior name="defaultBehavior"> 
     <serviceDebug includeExceptionDetailInFaults="true" /> 
     <serviceMetadata httpGetEnabled="true" /> 
    </behavior> 
    <behavior name=""> 
     <serviceMetadata httpGetEnabled="true" /> 
     <serviceDebug includeExceptionDetailInFaults="false" /> 
    </behavior> 
    <behavior name="ExecutionEngine.AccountsBehavior"> 
     <serviceMetadata httpGetEnabled="true"/> 
     <serviceDebug includeExceptionDetailInFaults="true" /> 
     <serviceCredentials> 
     <userNameAuthentication 
      userNamePasswordValidationMode="Custom" 
      customUserNamePasswordValidatorType="WebService.Services.Security.CustomValidator,WebService" /> 
     </serviceCredentials> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 



<bindings> 





    <wsHttpBinding> 
    <binding name="SafeServiceConf" maxReceivedMessageSize="65536"> 
     <readerQuotas maxStringContentLength="65536" maxArrayLength="65536" 
     maxBytesPerRead="65536" /> 
     <security mode="TransportWithMessageCredential"> 
     <message clientCredentialType="UserName" /> 
     </security> 
    </binding> 
    <binding name="CrmServiceEndpoint" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false"> 
     <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
     <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" /> 
     <security mode="Message"> 
     <transport clientCredentialType="Windows" proxyCredentialType="None" realm="" /> 
     <message clientCredentialType="Certificate" negotiateServiceCredential="false" algorithmSuite="Default" establishSecurityContext="false" /> 
     </security> 
    </binding> 
    <binding name="CrmServiceEndpointSSL" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false"> 
     <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
     <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" /> 
     <security mode="TransportWithMessageCredential"> 
     <transport clientCredentialType="None" proxyCredentialType="None" realm="" /> 
     <message clientCredentialType="Certificate" negotiateServiceCredential="true" algorithmSuite="Default" establishSecurityContext="false" /> 
     </security> 
    </binding> 
    </wsHttpBinding> 

</bindings> 


<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/> 

risposta

7

Esempio:

namespace WcfService1 
{ 
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)] 
    public class Service1 : IService1 
    { 
+0

Grazie. Puoi dirmi come abilitare la sessione e accedervi? – SexyMF

2

Hai provato ad aggiungere il seguente attributo alla tua classe di servizio?

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 

È possibile quindi utilizzare il HttpContext per accedere alla sessione in questo modo:

HttpContext.Current.Session 
+0

Se inserisci codice, XML o campioni di dati, ** per favore ** evidenzia queste righe nell'editor di testo e fai clic sul pulsante "esempi di codice" ('{}') sulla barra degli strumenti dell'editor per formattarlo in modo appropriato e evidenziare la sintassi! –

+0

Grazie! Questo è stato il mio primo post su StackOverflow :) Lo farò la prossima volta! –

Problemi correlati