现在的位置: 首页 > 综合 > 正文

cxf2.2.6+spring2.5.6+tomcat6.0.20创建webService

2018年06月08日 ⁄ 综合 ⁄ 共 8116字 ⁄ 字号 评论关闭

1、准备jar包,全部来自cxf2.2.6/lib下

2、配置web.xml

3、编写代码

interface:UserService

class: UserServiceImpl

entity:User

Dal :UserDao

4、编写applicationContext.xml

 

5、启动tomcat,

访问:http://127.0.0.1:8080/ytsd/service

 

发布成功,点击连接可以看到生成的wsdl

 

6、测试

在web-inf下建立test/testService.html

测试1:调用webservice的Insert方法

==============================================================================

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <title>Test UserManager Service</title>
        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
        <meta http-equiv="description" content="this is my page">
        <meta http-equiv="content-type" content="text/html; charset=UTF-8">
        <script type="text/javascript">
            function post(){
                var xmlHttp=false;
                if(!xmlHttp && typeof XMLHttpRequest != 'undefined'){
                    try{
                        xmlHttp = new XMLHttpRequest();
                    }catch(e){
                        xmlHttp = false;
                    }
                }
                if(!xmlHttp && window.createRequest){
                    try{
                        xmlHttp = window.createRequest();
                    }catch(e){
                        xmlHttp = false;
                    }
                }
                var dest = document.getElementById('destination').value;
                xmlHttp.open("POST",dest,true);
                xmlHttp.onreadystatechange=function(){
                    if(xmlHttp.readState==4){
                        document.getElementById('result').innerHTML=xmlHttp.responseText;
                    }
                }
                xmlHttp.setRequestHeader("Man","POST "+dest+" HTTP/1.1");
                xmlHttp.setRequestHeader("MessageType","CALL");
                xmlHttp.setRequestHeader("Content-Type","text/xml");
                var texta = document.getElementById('texta');
                var soapmess = texta.value;
                //alert(soapmess);
                xmlHttp.send(soapmess);
            }
           
        </script>

    </head>

    <body>
        <center>
            <h2>
                Test UserManager Service
            </h2>
            <form id="forma">
                <textarea rows="10" cols="80" id="texta"><?xml version="1.0" encoding="UTF-8"?><soap-env:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"><soap-env:Body><Insert><userId>200013</userId><userName>Tom zhang</userName><userEmail>tom@163.com</userEmail><userAge>35</userAge></Insert></soap-env:Body></soap-env:Envelope>
</textarea>
                <p></p>
                <input type="text" id="destination" size="50" value="http://127.0.0.1:8080/ytsd/service/UserManager">
                <p></p>
                <input type="button" onclick="post();" value="Submit" id="submit">           
            </form>
            <div id="container">
                Result:
                <hr/>
                <div id="result"></div>
                <hr/>
                <div id="soap"></div>
            </div>
        </center>
    </body>
</html>
===================================================================

测试2:调用webservice的GetUserById方法

<?xml
version="1.0" encoding="UTF-8"?><soap-env:Envelope
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"><soap-env:Body><GetUserById><userId>20001</

userId
></
GetUserById
></soap-env:Body></soap-env:Envelope>

 

测试2:调用webservice的GetAllUsers方法

<?xml
version="1.0" encoding="UTF-8"?><soap-env:Envelope
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"><soap-env:Body><GetAllUsers>

</GetAllUsers
></soap-env:Body></soap-env:Envelope>

 

 

 

【上篇】
【下篇】

抱歉!评论已关闭.