为什么WCF InstanceContextMode.PerSession不能通过https工作?
我对[ServiceBehavior(InstanceContextMode=InstanceContextMode.PerSession]有问题] 我有一个简单的wcf服务,它托管在IIS7中 服务代码:为什么WCF InstanceContextMode.PerSession不能通过https工作?,https,wcf,wcf-binding,Https,Wcf,Wcf Binding,我对[ServiceBehavior(InstanceContextMode=InstanceContextMode.PerSession]有问题] 我有一个简单的wcf服务,它托管在IIS7中 服务代码: [ServiceContract(SessionMode = SessionMode.Allowed)] public interface IService1 { [OperationContract] int SetMyValue(int val); [Opera
[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();//=>返回0
现在,当我将我的服务配置为使用https并使用证书传输安全性时,InstanceContextMode.PerSession的作用类似于InstanceContextMode.PerCall [ServiceBehavior(InstanceContextMode=InstanceContextMode.PerSession)]客户端的结果现在已更改: Service1Client客户端=新的Service1Client()
client.ClientCredentials.ClientCertificate.SetCertificate(StoreLocation.CurrentUser,StoreName.My,X509FindType.FindByThumbprint,“3D6CA7A6EB8A8977C958A3D8E446337B273E4E”)
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>
为什么珀西塞斯的行为像珀塞尔?我误解了什么 我通过HTTPS获得了会话支持 WSHttpBinding不支持传输安全(HTTPS)上的可靠会话 我没有使用wsHttpBinding,而是创建了一个自定义绑定:
<customBinding>
<binding configurationName="customReliableHttpBinding">
<reliableSession />
<textMessageEncoding/>
<httpsTransport authenticationScheme="Anonymous" requireClientCertificate="true"/>
</binding>
</customBinding>