客户端是采用jquery方式来做调用.但是这种调用,因为jquery这种调用你就得有消息体.我们得先拿到这种消息体.PersonService这个服务类有两个方法.

http://localhost:8080/cxf-web-server1/service/person?wsdl

http://localhost:8080/cxf-web-server1/service/person?wsdl是SOAP1.1才有用,SOAP1.2不行.

请求的消息体:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:q0="http://person.web.rl.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<q0:addPerson>
<arg0>
<address>北京</address>
<gender>男</gender>
<name>任亮</name>
</arg0>
</q0:addPerson>
</soapenv:Body>
</soapenv:Envelope>

响应的消息体,查询的时候的消息体.

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:getPersonAllResponse xmlns:ns2="http://person.web.rl.com/"><return><address>北京</address><gender>男</gender><name>任亮</name></return></ns2:getPersonAllResponse></soap:Body></soap:Envelope>

写客户端/cxf-web-4jquery-client/WebRoot/jquery_person_ws.html点添加的时候要调一次,点查询的时候又调一次.

服务的类的地址,服务的类的地址具体调哪一个方法.

上一节课的疑问,Ajax里面指定好了这是服务的类.但是没有指定具体我们要请求哪一个方法?直接从消息体就能分析出来我们是请求哪一个方法.

分析WSDL文档,从服务访问点集合PersonServiceService找到portType——PersonService之后.portType——PersonService就有了两个operation——addPerson和getPersonAll.每一个方法operation(报文)里面都有一个输入消息和输出消息.那么这个消息具体的约束是由谁约束?是由上面的这些Schema跟你做好了这种约束.那么它如何识别你调用哪个方法是根据消息来识别的.如果你传的是getPersonAll()这个消息,WebService它就知道能解析这个消息.addPerson正好对应着的是谁呢?它能解析addPerson这个东西.addPerson它代表了你调用的是哪个方法.

<arg0>
<address>北京</address>
<gender>男</gender>
<name>任亮</name>
</arg0>

<arg0></arg0>是方法main的参数.它是根据这个消息体addPerson来识别的.你在Ajax传这么一个消息它就知道你是调用addPerson这么一个消息.点添加添加成功之后

请求消息从这拿一下.getPersonAll的请求消息是

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:q0="http://person.web.rl.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<q0:getPersonAll/>
</soapenv:Body>
</soapenv:Envelope>

会一个其他都会了.append和appendTo啥区别呢?

新版chrome浏览器需要添加Chrome插件/扩展程序Charset.


<!DOCTYPE html>
<html>
<head>
<meta name="content-type" content="text/html; charset=UTF-8">
<title>jquery_person_ws.html</title>
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
$(function(){
$("#add").click(function (){
//获得Person基本数据
var name = $("#pname").val();//name还是采用id选择器.
var gender = $("#gender").val();
var address = $("#address").val();
//组装消息体
var data =
'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:q0="http://person.web.rl.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'
+ '<soapenv:Body>'
+ '<q0:addPerson>'
+ ' <arg0> '
+ ' <address>'+address+'</address>'
+ ' <gender>'+gender+'</gender>'
+ ' <name>'+name+'</name>'
+ ' </arg0>'
+ ' </q0:addPerson>'
+ '</soapenv:Body>'
+ '</soapenv:Envelope>';//消息体
$.ajax({
//JSON对象
url:'http://localhost:8080/cxf-web-server1/service/person',//服务的类的地址,服务的类的地址具体调哪一个方法.Ajax里面指定好了这是服务的类.但是没有具体指定我们要请求哪一个方法.具体要请求哪一个方法?
type:'post',//请求方式
dataType:'xml',//返回值的数据类型
contentType:'text/xml;charset=UTF-8',//指定发送的数据类型
data:data,//发送的消息体
success:function(responseText){//返回的是XML文档类型.
//解析消息体
//var returnObj = $(responseText).find("return");//通过$把responseText换成jquery文档类型,jquery的文档类型.jquery的文档类型你用jquery来查找就更简单了.
//通过jquery的方法来找return元素
//alert(returnObj.text());
alert("添加成功");//返回值就是void
},
error:function(){
alert('system error');//加分号规范一些
} }); });//点击事件 $("#select").click(function (){ //组装消息体
var data =
'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:q0="http://person.web.rl.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'
+'<soapenv:Body>'
+'<q0:getPersonAll/>'
+'</soapenv:Body>'
+'</soapenv:Envelope>';//消息体
$.ajax({
//JSON对象
url:'http://localhost:8080/cxf-web-server1/service/person',//服务的类的地址,服务的类的地址具体调哪一个方法.Ajax里面指定好了这是服务的类.但是没有具体指定我们要请求哪一个方法.具体要请求哪一个方法?
//不用变,依然是请求的是这个服务类.
type:'post',//请求方式
dataType:'xml',//返回值的数据类型
contentType:'text/xml;charset=UTF-8',//指定发送的数据类型
data:data,//发送的消息体
success:function(responseText){//返回的是XML文档类型.
//解析消息体
//把响应的消息解析一下,解析之后给它添加到这个div里面来.
$("#tdiv").empty();
var jqueryObj = $(responseText)//把responseText先转换成jquery对象,使用$把responseText转换成jquery object
var returns = jqueryObj.find("return");//每一个return它是一个对象
var result = '';
returns.each(function() {
//循环它可以拿到每一个return,放到div里面去
//先把address等基本数据给它解析出来
var pname = $(this).find('name').text();
var address = $(this).find('address').text();
var gender = $(this).find('gender').text();
result = result + pname + " " +gender + " " + address + "<br>"; }); //returns不是一个对象,是一个数组
$("#tdiv").append(result);//根据id选择器拿到div
},
error:function(){
alert('system error');//加分号规范一些
} }); });//点击事件 });
</script>
</head> <body>
姓名:<input type="text" id="pname"><br>
性别:<input type="text" id="gender"><br>
地址 :<input type="text" id="address"><br>
<input type="button" id="add" value="添加">
<input type="button" id="select" value="查询">
<div id="tdiv" style="border: 1px solid ;width: 400px;height: 400px;"> </div>
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<!-- 使用Spring的监听器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class><!-- 初始化Spring的容器,cxf.xml本身就是一个Spring的容器.可以把cxf.xml作为Spring的容器进行加载. -->
<!-- 能加载Spring文件的类,这个类叫什么? -->
</listener>
<context-param>
<param-name>contextConfigLocation</param-name><!-- param-name不能再指定config-location,而是要指定ContextLoaderListener里面读取Spring文件的那个Key -->
<param-value>classpath:cxf.xml</param-value>
</context-param>
<servlet>
<servlet-name>cxf</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<!--
<init-param>
<param-name>config-location</param-name>
<param-value>classpath:cxf.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
-->
</servlet>
<servlet-mapping>
<servlet-name>cxf</servlet-name>
<url-pattern>/service/*</url-pattern> <!-- 拦截这种请求 -->
</servlet-mapping>
</web-app>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:jaxrs="http://cxf.apache.org/jaxrs" xmlns:cxf="http://cxf.apache.org/core"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd">
<!-- 引入CXF Bean定义如下,早期的版本中使用 -->
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<!--
=========================配置类的形式webservice服务==================================
address:tomcat的host http://ip:port/projectName/service/后面的一端路径
implementor:指定具体的服务的类
-->
<!--
<jaxws:endpoint id="hello" address="/hello" implementor="com.rl.web.server.HelloService">
-->
<!-- 输入拦截器,打印输入的消息 -->
<!--
<jaxws:inInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingInInterceptor"></bean>
</jaxws:inInterceptors>
<jaxws:outInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingOutInterceptor"></bean>
</jaxws:outInterceptors>
</jaxws:endpoint>
-->
<!--
=======================配置带有接口的webservice服务=========================================
address:tomcat的host http://ip:port/projectName/service/后面的一端路径
http://ip:port/projectName/service/bye
implementor:指定具体的服务的类
serviceClass:服务接口的类
-->
<!--
<jaxws:server address="/bye" serviceClass="com.rl.web.server.inter.ByeInter">
-->
<!--
这里不是指定实例,而是指定实现类的类
服务接口的实现类
-->
<!--
<jaxws:serviceBean>
<bean class="com.rl.web.server.inter.ByeInterImpl"></bean>
</jaxws:serviceBean>
-->
<!-- 输入拦截器,打印输入的消息 -->
<!--
<jaxws:inInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingInInterceptor"></bean>
</jaxws:inInterceptors>
<jaxws:outInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingOutInterceptor"></bean>
</jaxws:outInterceptors>
</jaxws:server>
--> <jaxws:server address="/person" serviceClass="com.rl.web.person.PersonService"> <!--
这里不是指定实例,而是指定实现类的类
服务接口的实现类
--> <jaxws:serviceBean>
<bean class="com.rl.web.person.PersonServiceImpl"></bean>
</jaxws:serviceBean> <!-- 输入拦截器,打印输入的消息 --> <jaxws:inInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingInInterceptor"></bean>
</jaxws:inInterceptors>
<jaxws:outInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingOutInterceptor"></bean>
</jaxws:outInterceptors> </jaxws:server>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:jaxrs="http://cxf.apache.org/jaxrs" xmlns:cxf="http://cxf.apache.org/core"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd">
<!-- 引入CXF Bean定义如下,早期的版本中使用 -->
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<!--
=========================配置类的形式webservice服务==================================
address:tomcat的host http://ip:port/projectName/service/后面的一端路径
implementor:指定具体的服务的类
-->
<!--
<jaxws:endpoint id="hello" address="/hello" implementor="com.rl.web.server.HelloService">
-->
<!-- 输入拦截器,打印输入的消息 -->
<!--
<jaxws:inInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingInInterceptor"></bean>
</jaxws:inInterceptors>
<jaxws:outInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingOutInterceptor"></bean>
</jaxws:outInterceptors>
</jaxws:endpoint>
-->
<!--
=======================配置带有接口的webservice服务=========================================
address:tomcat的host http://ip:port/projectName/service/后面的一端路径
http://ip:port/projectName/service/bye
implementor:指定具体的服务的类
serviceClass:服务接口的类
-->
<!--
<jaxws:server address="/bye" serviceClass="com.rl.web.server.inter.ByeInter">
-->
<!--
这里不是指定实例,而是指定实现类的类
服务接口的实现类
-->
<!--
<jaxws:serviceBean>
<bean class="com.rl.web.server.inter.ByeInterImpl"></bean>
</jaxws:serviceBean>
-->
<!-- 输入拦截器,打印输入的消息 -->
<!--
<jaxws:inInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingInInterceptor"></bean>
</jaxws:inInterceptors>
<jaxws:outInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingOutInterceptor"></bean>
</jaxws:outInterceptors>
</jaxws:server>
-->
<!--
<jaxws:server address="/person" serviceClass="com.rl.web.person.PersonService">
-->
<!--
这里不是指定实例,而是指定实现类的类
服务接口的实现类
-->
<!--
<jaxws:serviceBean>
<bean class="com.rl.web.person.PersonServiceImpl"></bean> </jaxws:serviceBean>
-->
<!-- 输入拦截器,打印输入的消息 -->
<!--
<jaxws:inInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingInInterceptor"></bean>
</jaxws:inInterceptors>
<jaxws:outInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingOutInterceptor"></bean>
</jaxws:outInterceptors>
</jaxws:server>
-->
</beans>

day63-webservice 10.jquery的调用webservice小练习的更多相关文章

  1. Jquery ajax调用webservice总结

    jquery ajax调用webservice(C#)要注意的几个事项: 1.web.config里需要配置2个地方 <httpHandlers>      <remove verb ...

  2. Jquery Ajax 调用 WebService

    原文:http://www.cnblogs.com/andiki/archive/2010/05/17/1737254.html jquery ajax调用webservice(C#)要注意的几个事项 ...

  3. Jquery AJAX 调用WebService服务

    对Jquery+JSON+WebService的一点认识 文章不错:http://www.cnblogs.com/tyb1222/archive/2011/10/13/2210549.html Jqu ...

  4. 【学习篇:他山之石,把玉攻】jquery实现调用webservice

    1.webservice端 using System; using System.Collections.Generic; using System.Web; using System.Web.Ser ...

  5. jquery实现调用webservice

    1.webservice端 using System; using System.Collections.Generic; using System.Web; using System.Web.Ser ...

  6. Axis2 webservice 之使用java调用webservice

    在上一篇中写了一个简单了webservice,实现了一个sayHello功能.那么webservice写好之后我们如何使用Java程序来调用webservice呢? 一.java调用的webservi ...

  7. Java动态调用webService,axis2动态调用webService

    Java动态调用webService axis2动态调用webService >>>>>>>>>>>>>>>& ...

  8. 发布WebService到IIS和调用WebService

    一:在项目上右键单击,选择发布,如图 二:可以单击重命名,自定义网站的名字,发布方式为:文件系统,目标路径为要发布的文件的位置,它需要放到IIS的目录下面的 三:打开IIS管理器,右键单击网站,添加网 ...

  9. JEECG(二) JEECG框架下调用webservice java springmvc maven 调用 webservice

    JEECG系列教程二 如何在JEECG框架下使用webservice 本文所使用的webservice是c#开发的 其实无论是什么语言开发的webservice用法都一样 java springmvc ...

随机推荐

  1. 魅族和三星Galaxy 5.0webView 问题Android Crash Report - Native crash at /system/lib/libc.so caused by webvi

    解决办法是当前activity 销毁的时候 webView.destroy(); hine: ConnectedState (when=-2ms what= arg1=!CMD_RSSI_POLL : ...

  2. 怪异的Ubuntu

    怪异的Ubuntu 简单记录ubuntu上出现并且网上不好找到甚至压根找不到解决方案的疑难杂症. lvextend扩展逻辑卷的容量不能被系统检测到 问题发生在Ubuntu 16.04系统上. 逻辑卷/ ...

  3. 复习java基础第七天(反射)

    一:目标 Ø理解 Class 类 Ø理解 Java 的类加载机制 Ø学会使用 ClassLoader 进行类加载 Ø理解反射的机制 Ø掌握 Constructor.Method.Field 类的用法 ...

  4. OpenCV:OpenCV目标检测Hog+SWindow源代码分析

    参考文章:OpenCV中的HOG+SVM物体分类 此文主要描述出HOG分类的调用堆栈. 使用OpenCV作图像检测, 使用HOG检测过程,其中一部分源代码如下: 1.HOG 检测底层栈的检测计算代码: ...

  5. window phone 8 开发准备工作(一)

    一.下载安装Window phone SDK 1.Windows Phone SDK 8.0下载 http://www.microsoft.com/ZH-CN/download/details.asp ...

  6. python 生成测试报告并发送邮件

    前言: 使用unittest编写自动化测试脚本,执行脚本后可以很方便看到测试用例的执行情况. 但如果想向领导汇报工作,就需要提供更直观的测试报告. 思路: 使用unittest编写测试用例,HTMLT ...

  7. python PIL图像处理-图片上添加文字

    首先需要安装库pillow cmd安装命令:pip install pillow 安装完后,编写脚本如下: from PIL import Image, ImageDraw, ImageFont de ...

  8. Vue push() pop() shift() unshift() splice() sort() reverse() ...

    Vue 变异方法 push() 方法可向数组的末尾添加一个或多个元素,并返回新的长度. pop() 方法用于删除并返回数组的最后一个元素. shift() 方法用于把数组的第一个元素从其中删除,并返回 ...

  9. UVA1339 - Ancient Cipher 【字符串+排序】【紫书例题4.1】

    题意:给定两个字符串,你可以替换或者置换,替换是指可以将相同的字母替换为任意一个字母,而置换是指将字母替换为下一个,如A替换B,B替换为C,,,Z替换为A.你需要判断是否可以通过一系列操作使两个字符串 ...

  10. 43.mapping的理解

    主要知识点: mapping的理解     (1)往es里面直接插入数据,es会自动建立索引,同时建立type以及对应的mapping (2)mapping中就自动定义了每个field的数据类型. ( ...