以下是我从网上找的,和我的服务端的代码差不多
1.定义一个安全上下文,并且继承于SoapHeader类,服务用的是C#
public class SecurityContext : SoapHeader
...{
    public string UserID;
    public string Password;
}
UserID是定义的用户名,Password是密码,当然这个UserID和密码是可以通过数据库获得的,在这里,我们固定这两个变量的值2.在Web Service中定义一个公开的变量,类型是SecurityContext
public SecurityContext m_SecurityContext;
3.定义一个校验用户名和密码的方法private bool ValidateUser()
    ...{
        if (m_SecurityContext == null)
        ...{
            throw new Exception("没有指定用户名和密码");
        }
        
        //这里可以直接访问数据库来验证密码
        if (m_SecurityContext.UserID.ToLower() == (new AppSettingsReader()).GetValue("DTUser", typeof(string)).ToString().ToLower()
            && m_SecurityContext.Password == (string)(new AppSettingsReader()).GetValue("DTPassword", typeof(string)))
        ...{
            return true;
        }
        else
        ...{
            return false;
        }
    }4.在公开的,提供给客户调用的Web Service方法里调用校验的方法,如[WebMethod]
    [SoapHeader("m_SecurityContext")]
    public DataSet GetChangedDepts(string DeptCode)
    ...{
        if (!ValidateUser())
        ...{
            return null;
        }
       
        return m_ServiceAll.GetChangedDepts(DeptCode);
    }
以下是我项目里的客户端代码如下,用的是JAVA的AXIS2:RegisterEditForm form = (RegisterEditForm) o;
RPCServiceClient serviceClient = new RPCServiceClient();        Options options = serviceClient.getOptions();
        QName opSet1=
            new QName("XXX", "SecurityContext");
        options.setTo(targetEPR);
        QName opSetLog =
            new QName("XXX", "Register");
        Class[] returnTypes = new Class[] { String.class };
        
        Object[] opLogArgs = new Object[] {"f888888","88888888","[email protected]","FFF","192.168.10.169"};
        
        serviceClient.invokeBlocking(opSetLog,
         opLogArgs);
如何在客户端的代码中加入要进行验证的用户名和密码!谢