春天的熊

javascript 调用webservice

 看看时间戳,快有一个月没有过来更新了,因为最近的事情太多。求谅解。

 曾经是给perl的开发人员写的一个demo,他们用perl写的东西,来调用java实现的webservice(cxf或xfire),没想到又再次用到接下来的项目里。


   服务端用cxf实现,我这边用xfire写的调用不到,就想到了用javascript试试。成功了。代码如下:


  <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="http://www.lofter.com/blog/cnzhangleon/new/text/<%=basePath%>">
   
    <title>My JSP 'index.jsp' starting page</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">   
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="http://www.lofter.com/blog/cnzhangleon/new/text/styles.css">
    -->
    <script type="text/javascript" language="javascript">
        function PostRequestData(URL,data){
        var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        xmlhttp.Open("POST",URL, false);
        xmlhttp.SetRequestHeader ("Content-Type","text/xml; charset=utf-8");
        xmlhttp.SetRequestHeader ("SOAPAction","http://localhost:8080/WebServices/services/IBankingService");
        try {
            xmlhttp.Send(data);
            var result = xmlhttp.status;
        } catch(ex) {
            return("return: " + ex.description + "|" + ex.number);
        }  
        if(result==200) {
            return("return: " + xmlhttp.responseText);
        }
        xmlhttp = null;
    }
    function loadit(value){
        var url = 'http://localhost:8080/WebServices/services/IBankingService';
        var data ;
        var r;
        var encryptDN = 'MIIDjAYJKoZIhvcNAQcCoIIDfTCCA3kCAQExDTALBgkqhkiG9w0BAQUwCwYJKoZI';
       
        data = '<?xml version="1.0" encoding="utf-8"?>';
        data = data + '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">';
        data = data + '<soap:Body xmlns:m="http://www.example.org/stock">';
        data = data + '<m:accountingUnitInfo>';
        data = data + '<m:DN>CN=normal, E=normal@jit.com.cn, O=jit, C=cn</m:DN>';
        data = data + '<m:encryptDN>'+encryptDN+'</m:encryptDN>';
        data = data + '<m:encryptMD5>encryptMD5</m:encryptMD5>';
        data = data + '<m:filename>filename</m:filename>';
        data = data + '<m:filebuff>filebuff</m:filebuff>';
        data = data + '</m:accountingUnitInfo>';
        data = data + '</soap:Body>';
        data = data + '</soap:Envelope>';


        r=PostRequestData(url,data);
        document.write(r);
    }
   
    </script>
  </head>
 
  <body>
    <div onclick="loadit('5');">点击我!测试accountingUnitInfo接口的CA认证</div>
   
   
  </body>
</html>

------------------------------------下面是个小点的soap报文----------------------

    var data ;
        data = '<?xml version="1.0" encoding="utf-8"?>';
        data = data + '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://webservice.authentication.xxx.com/"><soapenv:Header/>';
        data = data + '<soapenv:Body>';
        data = data + '<web:validate>';
        data = data + '<arg0>'+tokenid+'</arg0>'; //tokenid-----是传过来的参数
        data = data + '<arg1>XXXX_JSZX_WCIP</arg1>';
        data = data + '<arg2>0</arg2>';
        data = data + '</web:validate>';
        data = data + '</soap:Body>';
        data = data + '</soap:Envelope>';

   
评论
热度(3)
  1. 小城,风带香春天的熊 转载了此文字
坚信上帝的延迟,并不是上帝的拒绝。

那些还没有到来的,总会在找寻和尝试中来到。

Here,成长的角落。

Q_Q:317886534