另一种选择是实施您自己的安全性。这是一个基本示例。
周转基金服务
在你的服务中,改变它ServiceBehavior
's InstanceContextMode
to PerSession
and ConcurrencyMode
to Single
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession, ConcurrencyMode = ConcurrencyMode.Single)]
public class SomeService : ISomeService
{
// ...
}
Add a Username
and Password
为您服务的财产。
public string UserName { [OperationContract] get; [OperationContract] set; }
public string Password { [OperationContract] get; [OperationContract] set; }
添加用于检查安全性的私有方法。
public void CheckSecurity()
{
if ((this.UserName == null || this.Password == null) ||
this.UserName == "username" && this.Password == "password"))
{
throw new FaultException("Unknown username or incorrect password.");
}
}
Then call the CheckSecurity
method in each of your service class constructor method.
public SomeServiceMethod1()
{
this.CheckSecurity();
// some method codes
}
客户申请
在您的客户端应用程序代码中,为每个实例设置服务用户名和密码,或者创建一个静态类来为您执行此操作。
您还可以尝试在用户名和密码中使用加密来增加安全性。
请注意,这只是为您添加另一个可能适合您需求的选项,但您应该始终尝试使用 Microsoft 的做事方式。