2010-12-09 2 views
1

나는 문제가있는 [인 ServiceBehavior (InstanceContextMode = InstanceContextMode.PerSession)]WCF InstanceContextMode.PerSession이 https를 통해 작동하지 않는 이유는 무엇입니까?

내가 7.

서비스 코드를 IIS에서 호스팅되는 간단한 WCF 서비스가 있습니다

[ServiceContract(SessionMode = SessionMode.Allowed)] 
public interface IService1 
{ 
    [OperationContract] 
    int SetMyValue(int val); 

    [OperationContract] 
    int GetMyValue(); 
} 

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)] 
public class Service1 : IService1 
{ 
    int MyValue = 0; 

    public int SetMyValue(int val) 
    { 
     MyValue = val; 
     return MyValue; 
    } 

    public int GetMyValue() 
    { 
     return MyValue; 
    } 

} 

모든 경우에 작동을 서비스 사이트는 http를 사용합니다. 예를 들어 [ServiceBehavior (InstanceContextMode = InstanceContextMode.PerSession)] 클라이언트의 결과는 다음과 같습니다.

Service1Client 클라이언트 = 새 Service1Client();
client.GetMyValue(); // ==> 0을 반환합니다.
client.SetMyValue (1); // ==> 1을 반환합니다.
client.GetMyValue(); // ==> 1을 반환합니다.
client.SetMyValue (6); // ==> 6을 반환합니다.
client.GetMyValue(); // ==> 반품 6

[인 ServiceBehavior (InstanceContextMode = InstanceContextMode.PerCall)]는 클라이언트 결과 : (

Service1Client 클라이언트 = 새로운 Service1Client);
client.GetMyValue(); // ==> 0을 반환합니다.
client.SetMyValue (1); // ==> 1을 반환합니다.
client.GetMyValue(); // ==> 0을 반환합니다.
client.SetMyValue (6); // ==> 6을 반환합니다.
client.GetMyValue(); // ==> returns 0

이제 인증서를 사용하여 https 및 전송 보안을 사용하도록 서비스를 구성하면 InstanceContextMode.PerSession은 InstanceContextMode.PerCall과 같은 역할을합니다.

[인 ServiceBehavior (InstanceContextMode = InstanceContextMode.PerSession)] 클라이언트에 결과가 바뀌된다

Service1Client 클라이언트 = 새로운 Service1Client을();
client.ClientCredentials.ClientCertificate.SetCertificate (StoreLocation.CurrentUser, StoreName.My, X509FindType.FindByThumbprint, "3d6ca7a6ebb8a8977c958a3d8e4436337b273e4e");
client.GetMyValue(); // ==> 0을 반환합니다.
client.SetMyValue (1); // ==> 1을 반환합니다.
client.GetMyValue(); // ==> 0을 반환합니다.
client.SetMyValue (6); // ==> 6을 반환합니다.
client.GetMyValue(); // ==> 0

내 서비스의 web.config는 반환 :

<bindings> 
    <wsHttpBinding> 
    <binding name="wsHttpEndpointBinding"> 
     <security mode="Transport"> 
     <transport clientCredentialType="Certificate"/> 
     </security> 
    </binding> 
    </wsHttpBinding> 
</bindings> 

<services> 
    <service behaviorConfiguration="ServiceBehavior" name="WcfServiceLibrary1.Service1"> 
    <endpoint address="" binding="wsHttpBinding" bindingConfiguration="wsHttpEndpointBinding" 
     name="wsHttpEndpoint" contract="WcfServiceLibrary1.IService1" /> 
    </service> 
</services> 

<behaviors> 
    <serviceBehaviors> 
    <behavior name="ServiceBehavior"> 
     <serviceMetadata httpsGetEnabled="true" httpGetEnabled="false"/> 
     <serviceDebug includeExceptionDetailInFaults="true"/> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 

왜 PerSession 이와이 PerCall 같은 역할을? 무엇을 잘못 구성 했습니까?

답변

2

HTTPS를 통한 세션 지원이 가능합니다.

WSHttpBinding은 전송 보안 (HTTPS)을 통한 안정적인 세션을 지원하지 않습니다.

<customBinding> 
    <binding configurationName="customReliableHttpBinding"> 
    <reliableSession /> 
    <textMessageEncoding/> 
    <httpsTransport authenticationScheme="Anonymous" requireClientCertificate="true"/> 
    </binding> 
</customBinding> 
: WsHttpBinding과 사용의

, 나는 사용자 지정 바인딩을 생성

관련 문제