金色坐标

关注互联网和IT科技的个人博客

« Tomcat的优化配置JDK1.4信息传递安全性之消息摘要 »

怎么调用基于SSL的Web Service

首先:在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();
  }
 }
}




原创文章,如转载请注明:转载自金色坐标 [ http://www.kingxy.com/ ]

本文链接地址:http://www.kingxy.com/archives/8.html
  • 相关文章:

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

订阅博客

  • 订阅我的博客:订阅我的博客
  • 关注新浪微博:关注新浪微博
  • 关注腾讯微博:关注腾讯微博
  • 通过Google订阅本站
  • 通过鲜果订阅本站
  • 通过电子邮件订阅
  • 本站支持WAP访问

Search

Google

最新评论及回复

最近发表

金色坐标博客——京ICP备09009094号

本站采用创作共用版权协议, 要求署名、非商业用途和保持一致. 转载本站内容必须也遵循“署名-非商业用途-保持一致”的创作共用协议.
KingXY Blog - This site is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License.