开发者

Why WCF InstanceContextMode.PerSession is not working over https?

开发者 https://www.devze.com 2023-01-29 10:10 出处:网络
I have problems with[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession )] I have simple wcf service, which is hosted in IIS 7.

I have problems with [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession )]

I have simple wcf service, which is hosted in IIS 7.

Service code:

[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;
    }

}

Everything works if service site uses http. For example [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession )] result for client is:

Service1Client client = new Service1Client();

client.GetMyValue(); //==> returns 0

client.SetMyValue(1); //==> returns 1

client.GetMyValue(); //==> returns 1

client.SetMyValue(6); //==> returns 6

client.GetMyValue(); //==> returns 6

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall )] result for client is:

Service1Client client = new Service1Client();

client.GetMyValue(); //==> returns 0

client.SetMyValue(1); //==> returns 1

client.GetMyValue(); //==> returns 0

client.SetMyValue(6); //==> returns 6

client.GetMyValue(); //==> returns 0

Now when I configure my service to use https and transport security with certificate InstanceContextMode.PerSession acts like InstanceContextMode.PerCall.

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession )] result for client is now changed:

Service1Client client = new Service1Client();

client.ClientCredentials.ClientCertificate.SetCertificate( StoreLocation.CurrentUser, StoreNa开发者_JAVA百科me.My, X509FindType.FindByThumbprint, "3d6ca7a6ebb8a8977c958a3d8e4436337b273e4e");

client.GetMyValue(); //==> returns 0

client.SetMyValue(1); //==> returns 1

client.GetMyValue(); //==> returns 0

client.SetMyValue(6); //==> returns 6

client.GetMyValue(); //==> returns 0

My service web.config is:

<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>   

Why PerSession acts like PerCall? What have I misconfigured?


I got session support working over HTTPS.

WSHttpBinding does not support reliable sessions over transport security (HTTPS).

Instead of using wsHttpBinding, I created a custom binding:

<customBinding>
  <binding configurationName="customReliableHttpBinding">
    <reliableSession />
    <textMessageEncoding/>
    <httpsTransport authenticationScheme="Anonymous" requireClientCertificate="true"/>
  </binding>
</customBinding>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号