2011-10-16 12 views
6

मुझे अपनी डब्ल्यूसीएफ सेवा में सत्र सक्षम करने की आवश्यकता है। तो मैं करने के लिए:WCF aspNetCompatibilityEnabled = "true" एक अपवाद उठाएं (लोड करने में विफल)

<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/> 

जब मैं यह है कि मैं एक अपवाद मिलता है: क्योंकि यह ASP.NET अनुकूलता का समर्थन नहीं करता

सेवा सक्रिय नहीं किया जा सकता है। इस एप्लिकेशन के लिए एएसपी.NET संगतता सक्षम है। web.config में ASP.NET संगतता मोड बंद करें या RequirementsMode सेटिंग के साथ जोड़ने के सेवा प्रकार के AspNetCompatibilityRequirements विशेषता के रूप में 'अनुमति' या 'आवश्यक'

यह मेरा 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"/> 

उत्तर

7

उदाहरण:

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

धन्यवाद। क्या आप मुझे बता सकते हैं कि सत्र को कैसे सक्षम किया जाए और उस तक पहुंच कैसे प्राप्त करें? – SexyMF

2

क्या आपने अपनी सेवा कक्षा में निम्न योगदान जोड़ने का प्रयास किया है?

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 

फिर आप इस तरह सत्र तक पहुँचने के लिए HttpContext उपयोग कर सकते हैं:

HttpContext.Current.Session 
+0

यदि आप कोड, एक्सएमएल या डेटा नमूने पोस्ट करते हैं, ** कृपया ** टेक्स्ट एडिटर में उन पंक्तियों को हाइलाइट करें और संपादक टूलबार पर "कोड नमूने" बटन ('{}') पर क्लिक करें ताकि इसे अच्छी तरह प्रारूपित किया जा सके और इसे हाइलाइट किया जा सके! –

+0

धन्यवाद! यह stackoverflow पर मेरी पहली पोस्ट थी :) मैं अगली बार यह करूँगा! –

संबंधित मुद्दे