2011-10-16 2 views
6

내 WCF 서비스에서 세션을 활성화해야합니다. 은 그래서 나는이에 :WCF aspNetCompatibilityEnabled = "true"예외 발생 (로드 실패)

<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/> 

나는 예외 얻을 수행은 ASP.NET에게 호환성을 지원하지 않기 때문에

서비스가 활성화 할 수 없습니다. 이 응용 프로그램에서 ASP.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> 

,691 363,210

<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

코드, XML 또는 데이터 샘플을 게시하는 경우 텍스트 편집기에서 해당 행을 강조 표시하고 편집기 툴바에서 "코드 샘플"버튼 ('{}) '을 클릭하여 멋지게 형식을 지정하고 구문을 강조 표시하십시오! –

+0

고마워요! 이것은 stackoverflow 내 첫 번째 게시물 :) 나는 다음에 그것을 할거야! –

관련 문제