No.1 先定义一个SoapHeader
/// <summary>
/// 定义SoapHeader.
/// </summary>
public class CredentialSoapHeader : SoapHeader
{
    public string Username;
    public string PasswordHash;
    public string SecurityKey;
}
-------------------------------------------------------
No.2 定义安全类,继承WebService。并提供验证方法。
public class SecureWebService : WebService
{
    public CredentialSoapHeader Credentials;
    protected string VerifyCredentials()
    {
        if (this.Credentials == null
        || this.Credentials.Username == null
        || this.Credentials.PasswordHash == null)
        {
            throw new SoapException("没有提供信任令牌",
                SoapException.ClientFaultCode, "Security");
        }
        return CheckCredential(this.Credentials);
    }
}
----------------------------------------------------------------------
No.3 让你发布的webservice继承你的安全类。
public class SecureService : SecureWebService
{

    public SecureService()
    {

        //如果使用设计的组件,请取消注释以下行
        //InitializeComponent();
    }
}
-----------------------------------------------------------
No.4发布你的Webservice。在客户端对SoapHeader赋值,调用Webservice。完成。

相关文章:

  • 2021-09-07
  • 2022-01-17
  • 2021-05-31
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-01
猜你喜欢
  • 2022-02-09
  • 2022-12-23
  • 2021-10-16
  • 2021-12-22
  • 2021-07-09
  • 2022-12-23
  • 2021-09-07
相关资源
相似解决方案