客户端及服务端已经ok了,那么就看看运行效果吧
先运行服务端的main函数
Server server=new Server();
server.test(); //简单的不带usernametoken的WS
//server.testUserNameToken();// 启用usernametoken的WS
再启动客户端的main函数
WSClient client=new WSClient();
client.test();//测试PAYLOAD模式,不使用userNameToken身份验证机制
//client.testUserNameToken();//测试MESSAGE模式,使用userNameToken身份验证机制
客户端显示
<?xml version="1.0" encoding="UTF-8"?><ns2:getPersonResponse xmlns:ns2="http://service.test/"><return><age>30</age><userName>jack's father.</userName></return></ns2:getPersonResponse>
再看看username token验证怎样
服务端运行:
Server server=new Server();
// server.test(); //简单的不带usernametoken的WS
server.testUserNameToken();// 启用usernametoken的WS
客户端运行:
WSClient client=new WSClient();
//client.test();//测试PAYLOAD模式,不使用userNameToken身份验证机制
client.testUserNameToken();//测试MESSAGE模式,使用userNameToken身份验证机制
运行结果:
<?xml version="1.0" encoding="UTF-8" standalone="no"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Header><wsse:Securityxmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" soap:mustUnderstand="1"><wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UsernameToken-1"><wsse:Username>IamServer</wsse:Username><wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">sssss</wsse:Password></wsse:UsernameToken></wsse:Security></soap:Header><soap:Body><ns2:getPersonResponsexmlns:ns2="http://service.test/"><return><age>30</age><userName>JACK's father.</userName></return></ns2:getPersonResponse></soap:Body></soap:Envelope>
补充一点:wsdl中的上面的arg0看着是不是不顺眼,还有一些参数名称是不是也看着不舒服?ok,那就继续学习cxf的。还记得Person类上面的@XmlRootElement(name="PersonName")吧,它就可以重命名,其它参数也是一样的机制,这就是java的jaxb了,继续学习吧