如何使用nusoap lib创建nusoap服务器,并使用Javascript调用

时间:2016-11-21 08:44:04

标签: javascript php soap-client nusoap

我在我的localhost中使用nusoap-0.9.5 php制作nusoap server.php文件, 现在在index.html文件中,我该如何调用" getmessage"使用javascript的函数,例如:

以下代码无效..请帮助..

    <?php //---server.php--begin---(php) 
    require_once("lib/nusoap.php"); //liberary
    $server = new nusoap_server(); 
    $server->configureWSDL("myService","urn:service1"); // configuare WSDL
    function getmessage($message){
        return "Welcome ".$message;
    }
    $server->register(
        "getmessage",
        array("name"=>"xsd:string"), //input
        array("sum"=>"xsd:string") //output
    );
    //http listener
    $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA: '';
    $server->service($HTTP_RAW_POST_DATA);
    //---server.php--end---
   ?>

------------------- Javascript SOAP Client --------------------

        <!---index.html--begin---(javascript html)--->
        <SCRIPT language='javascript' src='soapclient.js'></SCRIPT>
        <SCRIPT>
            var url = "http://localhost/server.php?wsdl";
            function getmessage()
            {
                var pl = new SOAPClientParameters();
                pl.add("name", document.frmDemo.txtName.value);
                SOAPClient.invoke(url, "getmessage", pl, true, getmessage_callBack);
            }
            function getmessage_callBack(r)
            {
                alert(r);
            }

     </SCRIPT>
    <form id="frmDemo" name="frmDemo" action="" method="post">
        <input name="txtName" id="txtName" value="Matteo" type="text">
        <input type="button" value="click here" name="button"  onClick="getmessage();"> <br>
    </form>

      <!---index.html--end--->

1 个答案:

答案 0 :(得分:0)

Javascript没有稳定的soap库,您必须制作它或使用任何开发人员定制的简单库...例如,转到此链接并执行此操作: https://www.ibm.com/developerworks/library/ws-wsajax/