一、Web Service端的设计

先从SoapHeader继承一个自定义类CredentialSoapHeader,该类包含用户名和密码:
WebService安全篇public class CredentialSoapHeader : SoapHeader
}

在WebService类里面创建一个属性Credentials,类型为CredentialSoapHeader:
WebService安全篇public class IssueVisionServices : WebService
}

在WebMethod的方法上使用SoapHeader标识,成员名称为"Credentials":
WebService安全篇[WebMethod(Description="Returns the lookup tables for IssueVision.")]
WebService安全篇[SoapHeader(
"Credentials")]
WebService安全篇
public IVDataSet GetLookupTables()
}

public class SecurityHelper 
{
    
// verifies the clients credentials
    public static void VerifyCredentials(IssueVisionServices service) 
    {
        String userName 
= service.Credentials.Username;
        String password 
= service.Credentials.Password;
        
// 按照userName 和 password 进行授权验证
        WebService安全篇
    }
}

二、客户端对Web Service的调用

WebService安全篇private static IssueVisionServices GetWebServiceReference()
}

相关文章: