首先:在Weblgoic上配好双向SSL。
第二:部署好Web Service。
第三:编写web service 调用程序。
例子:
wonsslBean是一个简单的Statless SessionBean
public class wonsslBean implements SessionBean {
SessionContext sessionContext;
public void ejbCreate() throws CreateException {
/**@todo Complete this method*/
}
public void ejbRemove() {
/**@todo Complete this method*/
}
public void ejbActivate() {
/**@todo Complete this method*/
}
public void ejbPassivate() {
/**@todo Complete this method*/
}
public void setSessionContext(SessionContext sessionContext) {
this.sessionContext = sessionContext;
}
public String getName(){
return "zhang san";
}
}
用apache axis toolkit生成Web Service 并部署在服务器上,
下面是客户端调用程序:
import org.apache.axis.client.Service;
import org.apache.axis.client.Call;
import javax.xml.namespace.QName;
public class TestClient {
public static void main(String [] args) {
try {
//加入信任库和密钥库
System.setProperty("javax.net.ssl.keyStore", "C:/work_space/certkey/wst/test.jks");
System.setProperty("javax.net.ssl.keyStorePassword", "880102");
System.setProperty("javax.net.ssl.trustStore","C:/work_space/certkey/wst/test.jks");
//web service调用
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress( new java.net.URL("https://sslexp:7002/wos/services/wonssl") );
call.setOperationName(new QName("getName"));
String ret = (String) call.invoke(new Object[] { });
System.out.println("Sent 'Hello!', name '" + ret + "'");
} catch (Exception e) {
System.err.println(e.toString());
e.printStackTrace();
}
}
}





