基于extjs webservicess 开发服务和客户端

> 运用XFire开发WebServices服务端
运用XFire开发WebServices服务端
luwenjuan & &
发布时间: & &
浏览:6 & &
回复:0 & &
悬赏:0.0希赛币
使用XFire开发WebServices服务端
本文所用到的WebServices服务端,取自我的上一篇文章中的例子——使用XFire开发WebServices服务端 这里并未涉及到JSR 181 Annotations 的相关应用,具体的三种方式如下① 通过WSDL地址来创建动态客户端 ② 通过服务端提供的接口来创建客户端 ③ 使用Ant通过WSDL文件来生成客户端 第一种方式:通过WSDL地址来创建动态客户端 view plaincopy to clipboardprint package com.jadyer.&& import java.net.MalformedURLE&& import java.net.URL;&& import org.codehaus.xfire.client.C&& /**&
* 通过WSDL来创建动态客户端&
* @see 此时需要在项目中引入XFire 1.2 Core Libraries和XFire 1.2 HTTP Client Libraries&
*/& public class ClientFromWSDL {&& &&& public static void main(String[] args) throws MalformedURLException, Exception {&& &&&&&&& Client client = new Client(new URL(""));&& &&&&&&& Object[] results11 = client.invoke("sayHello", new Object[]{"Jadyer22"});&& &&&&&&& System.out.println(results11[0]);&& &&& }&& }& package com.jadyer.import java.net.MalformedURLEimport java.net.URL;import org.codehaus.xfire.client.C/** * 通过WSDL来创建动态客户端 * @see 此时需要在项目中引入XFire 1.2 Core Libraries和XFire 1.2 HTTP Client Libraries */public class ClientFromWSDL { public static void main(String[] args) throws MalformedURLException, Exception {
Client client = new Client(new URL(""));
Object[] results11 = client.invoke("sayHello", new Object[]{"Jadyer22"});
System.out.println(results11[0]); }} 第二种方式:通过服务端提供的端口来创建客户端 view plaincopy to clipboardprint package com.jadyer.&& import java.net.MalformedURLE&& import java.util.L&& import org.codehaus.xfire.client.XFireProxyF&& import org.codehaus.xfire.service.S&& import org.codehaus.xfire.service.binding.ObjectServiceF&& import com.jadyer.model.P&& import com.jadyer.model.U&& import com.jadyer.server.HelloS&& /**&
* 通过Web服务端提供的接口来创建客户端&
* @see 客户端必须提供一个与服务端完全一致的接口,包名也要一致&
* @see 在本例中,需要在客户端(即该项目)中提供HelloService.java接口,以及Person和User两个POJO类&
* @see 并且此时需要在项目中引入XFire 1.2 Core Libraries和XFire 1.2 HTTP Client Libraries&
*/& public class ClientFromInterface {&& &&& public static void main(String[] args)throws MalformedURLException{&& &&&&&&& //首先使用XFire的ObjectServiceFactory从HelloService接口创建一个服务模型serviceModel&& &&&&&&& //serviceModel包含服务的说明,换句话说,就是服务的元数据&& &&&&&&& //Create a metadata of the service&& &&&&&&& Service serviceModel = new ObjectServiceFactory().create(HelloService.class);&& &&&&&&&&&& &&&&&&& //访问的地址&& &&&&&&& String serviceURL = "";&& &&&&&&&&&& &&&&&&& //通过查看org.codehaus.xfire.client.XFireProxyFactory源码发现&& &&&&&&& //下面两行代码与这里直接new XFireProxyFactory()的作用是等效的&& &&&&&&& //XFire xfire = XFireFactory.newInstance().getXFire();&& &&&&&&& //XFireProxyFactory factory = new XFireProxyFactory(xfire);&& &&&&&&& //为XFire获得一个代理工厂对象&& &&&&&&& //Create a proxy for the deployed service&& &&&&&&& XFireProxyFactory factory = new XFireProxyFactory();&& &&&&&&&&&& &&&&&&& //通过proxyFactory,使用服务模型serviceModel和服务端点URL(用来获得WSDL)&& &&&&&&& //得到一个服务的本地代理,这个代理就是实际的客户端&& &&&&&&& HelloService client = (HelloService)factory.create(serviceModel, serviceURL);&& &&&&&&&&&& &&&&&&& /**& &&&&&&&& * Invoke the service& &&&&&&&& * @see 调用服务的本地代理(即实际的客户端)中的方法,便得到我们需要的WebServcie& &&&&&&&& */& &&&&&&&&&& &&&&&&& /*--处理简单对象--*/& &&&&&&& String serviceResponse = client.sayHello("Jadyer11");&& &&&&&&& System.out.println(serviceResponse);&& &&&&&&&&&& &&&&&&& /*--处理对象--*/& &&&&&&& User u = new User();&& &&&&&&& u.setName("Jadyer99");&& &&&&&&& Person pp = client.getPerson(u);&& &&&&&&& System.out.println(pp.getName());&& &&&&&&&&&& &&&&&&& /*--处理List--*/& &&&&&&& List&Person& personList = client.getPersonList(24, "Jadyer88");&& &&&&&&& for(Person p : personList){&& &&&&&&&&&&& System.out.println(p.getName());&& &&&&&&& }&& &&& }&& }& package com.jadyer.import java.net.MalformedURLEimport java.util.Limport org.codehaus.xfire.client.XFireProxyFimport org.codehaus.xfire.service.Simport org.codehaus.xfire.service.binding.ObjectServiceFimport com.jadyer.model.Pimport com.jadyer.model.Uimport com.jadyer.server.HelloS/** * 通过Web服务端提供的接口来创建客户端 * @see 客户端必须提供一个与服务端完全一致的接口,包名也要一致 * @see 在本例中,需要在客户端(即该项目)中提供HelloService.java接口,以及Person和User两个POJO类 * @see 并且此时需要在项目中引入XFire 1.2 Core Libraries和XFire 1.2 HTTP Client Libraries */public class ClientFromInterface { public static void main(String[] args)throws MalformedURLException{
//首先使用XFire的ObjectServiceFactory从HelloService接口创建一个服务模型serviceModel
//serviceModel包含服务的说明,换句话说,就是服务的元数据
//Create a metadata of the service
Service serviceModel = new ObjectServiceFactory().create(HelloService.class);
//访问的地址
String serviceURL = "";
//通过查看org.codehaus.xfire.client.XFireProxyFactory源码发现
//下面两行代码与这里直接new XFireProxyFactory()的作用是等效的
//XFire xfire = XFireFactory.newInstance().getXFire();
//XFireProxyFactory factory = new XFireProxyFactory(xfire);
//为XFire获得一个代理工厂对象
//Create a proxy for the deployed service
XFireProxyFactory factory = new XFireProxyFactory();
//通过proxyFactory,使用服务模型serviceModel和服务端点URL(用来获得WSDL)
//得到一个服务的本地代理,这个代理就是实际的客户端
HelloService client = (HelloService)factory.create(serviceModel, serviceURL);
* Invoke the service
* @see 调用服务的本地代理(即实际的客户端)中的方法,便得到我们需要的WebServcie
/*--处理简单对象--*/
String serviceResponse = client.sayHello("Jadyer11");
System.out.println(serviceResponse);
/*--处理对象--*/
User u = new User();
u.setName("Jadyer99");
Person pp = client.getPerson(u);
System.out.println(pp.getName());
/*--处理List--*/
List&Person& personList = client.getPersonList(24, "Jadyer88");
for(Person p : personList){
System.out.println(p.getName());
} }} 这是它要用到的接口和两个POJO类 view plaincopy to clipboardprint /**&
* Web服务提供给客户端的接口&
* @see 这是第二种方式创建的客户端,要用到的接口&
*/& package com.jadyer.&& import java.util.L&& import com.jadyer.model.P&& import com.jadyer.model.U&& public interface HelloService {&& &&& public String sayHello(String name);&& &&& public Person getPerson(User u);&& &&& public List&Person& getPersonList(Integer age, String name);&& }&& /**&
* 第二种方式创建的客户端,要用到的两个POJO类&
*/& package com.jadyer.&& public class User {&& &&& private S&& &&& /*--getter和setter略--*/& }&& package com.jadyer.&& public class Person {&& &&& private I&& &&& private S&& &&& /*--getter和setter略--*/& }& /** * Web服务提供给客户端的接口 * @see 这是第二种方式创建的客户端,要用到的接口 */package com.jadyer.import java.util.Limport com.jadyer.model.Pimport com.jadyer.model.Upublic interface HelloService { public String sayHello(String name); public Person getPerson(User u); public List&Person& getPersonList(Integer age, String name);}/** * 第二种方式创建的客户端,要用到的两个POJO类 */package com.jadyer.public class User { private S /*--getter和setter略--*/}package com.jadyer.public class Person { private I private S /*--getter和setter略--*/} 第三种方式:使用Ant通过WSDL文件来生成客户端 view plaincopy to clipboardprint package com.jadyer.&& /**&
* 使用Ant通过WSDL生成客户端&
* @see 这里的ClientFromAnt.java是我自己创建的,并非Ant生成&
* @see 这里要用到的JAR有:xfire-all-1.2.6.jar以及\\xfire-distribution-1.2.6\\lib\\目录中的所有JAR包&
* @see 我们需要把这些JAR包都拷贝到Web Project\\WebRoot\\WEB-INF\\lib\\目录中&
* @see 然后把build.xml和MyFirstXFireServer.wsdl都拷贝到下Web Project的根目录下即可&
* @see 关于MyFirstXFireServer.wsdl文件,是我在WebServices服务启动后&
* @see 访问然后将其另存得到的&
*/& public class ClientFromAnt {&& &&& public static void main(String[] args) {&& &&&&&&& XFireServerClient client = new XFireServerClient();&& &&&&&&& //String url = "";&& &&&&&&& //String result = client.getXFireServerHttpPort(url).sayHello("Jadyer33");&& &&&&&&& //上面的两行代码,与下面的这一行代码,同效~~&& &&&&&&& String result = client.getXFireServerHttpPort().sayHello("Jadyer33");&& &&&&&&&&&& &&&&&&& System.out.println(result);&& &&& }&& }& package com.jadyer./** * 使用Ant通过WSDL生成客户端 * @see 这里的ClientFromAnt.java是我自己创建的,并非Ant生成 * @see 这里要用到的JAR有:xfire-all-1.2.6.jar以及\\xfire-distribution-1.2.6\\lib\\目录中的所有JAR包 * @see 我们需要把这些JAR包都拷贝到Web Project\\WebRoot\\WEB-INF\\lib\\目录中 * @see 然后把build.xml和MyFirstXFireServer.wsdl都拷贝到下Web Project的根目录下即可 * @see 关于MyFirstXFireServer.wsdl文件,是我在WebServices服务启动后 * @see 访问然后将其另存得到的 */public class ClientFromAnt { public static void main(String[] args) {
XFireServerClient client = new XFireServerClient();
//String url = "";
//String result = client.getXFireServerHttpPort(url).sayHello("Jadyer33");
//上面的两行代码,与下面的这一行代码,同效~~
String result = client.getXFireServerHttpPort().sayHello("Jadyer33");
System.out.println(result); }} 用到的Ant文件,如下 view plaincopy to clipboardprint & xml version="1.0" encoding="UTF-8" $>$ &project name="wsgen" default="wsgen" basedir="."$>$ &&& &path id="classpathId"$>$ &&&&&&& &fileset dir="./WebRoot/WEB-INF/lib"$>$ &&&&&&&&&&& &include name="*.jar" /$>$ &&&&&&& &/fileset$>$ &&& &/path$>$ &&&&&& &&& &taskdef classpat name="wsgen" classname="org.codehaus.xfire.gen.WsGenTask"/$>$ &&&&&& &&& &target name="wsgen" description="generate client"$>$ &&&&&&& &wsgen outputDirectory="./src/" wsdl="MyFirstXFireServer.wsdl" binding="xmlbeans" package="com.jadyer.client" overwrite="true"/$>$ &&& &/target$>$ &/project$>$ & xml version="1.0" encoding="UTF-8" &&project name="wsgen" default="wsgen" basedir="."& &path id="classpathId"&
&fileset dir="./WebRoot/WEB-INF/lib"&
&include name="*.jar" /&
&/fileset& &/path&
&taskdef classpat name="wsgen" classname="org.codehaus.xfire.gen.WsGenTask"/&
&target name="wsgen" description="generate client"&
&wsgen outputDirectory="./src/" wsdl="MyFirstXFireServer.wsdl" binding="xmlbeans" package="com.jadyer.client" overwrite="true"/& &/target&&/project& 也可以使用下面的这个Ant文件 view plaincopy to clipboardprint & xml version="1.0" encoding="UTF-8" $>$ &project name="xfireAnt" basedir="." default="createClientCode"$>$ &&& &property name="xfirelib" value="${basedir}/WebRoot/WEB-INF/lib"/$>$ &&& &property name="sources" value="${basedir}/src"/$>$ &&& &path id="classpath"$>$ &&&&&&& &fileset dir="${xfirelib}"$>$ &&&&&&&&&&& &include name="*.jar"/$>$ &&&&&&& &/fileset$>$ &&& &/path$>$ &&&&&&&&&& &&& &target name="createClientCode"$>$ &&&&&&& &taskdef name="wsgen" classname="org.codehaus.xfire.gen.WsGenTask" classpat/$>$ &&&&&&& &wsgen outputDirectory="${sources}" wsdl="" package="com.jadyer.client" overwrite="true"/$>$ &&& &/target$>$ &/project$>$ & xml version="1.0" encoding="UTF-8" &&project name="xfireAnt" basedir="." default="createClientCode"& &property name="xfirelib" value="${basedir}/WebRoot/WEB-INF/lib"/& &property name="sources" value="${basedir}/src"/& &path id="classpath"&
&fileset dir="${xfirelib}"&
&include name="*.jar"/&
&/fileset& &/path& &&&
&target name="createClientCode"&
&taskdef name="wsgen" classname="org.codehaus.xfire.gen.WsGenTask" classpat/&
&wsgen outputDirectory="${sources}" wsdl="" package="com.jadyer.client" overwrite="true"/& &/target&&/project& 最后我再把MyFirstXFireServer.wsdl的内容,附加上 view plaincopy to clipboardprint & xml version="1.0" encoding="UTF-8" $>$ &wsdl:definitions targetNamespace=""& &&& xmlns:tns=""& &&& xmlns:wsdlsoap=""& &&& xmlns:soap12=""& &&& xmlns:xsd=""& &&& xmlns:soapenc11=""& &&& xmlns:soapenc12=""& &&& xmlns:soap11=""& &&& xmlns:wsdl=""$>$ &&& &wsdl:types$>$ &&&&&&& &xsd:schema xmlns:xsd=""& &&&&&&&&&&&&&&&&&&& attributeFormDefault="qualified"& &&&&&&&&&&&&&&&&&&& elementFormDefault="qualified"& &&&&&&&&&&&&&&&&&&& targetNamespace=""$>$ &&&&&&&&&&& &xsd:element name="sayHello"$>$ &&&&&&&&&&&&&&& &xsd:complexType$>$ &&&&&&&&&&&&&&&&&&& &xsd:sequence$>$ &&&&&&&&&&&&&&&&&&&&&&& &xsd:element maxOccurs="1" minOccurs="1" name="in0" nillable="true" type="xsd:string" /$>$ &&&&&&&&&&&&&&&&&&& &/xsd:sequence$>$ &&&&&&&&&&&&&&& &/xsd:complexType$>$ &&&&&&&&&&& &/xsd:element$>$ &&&&&&&&&&& &xsd:element name="sayHelloResponse"$>$ &&&&&&&&&&&&&&& &xsd:complexType$>$ &&&&&&&&&&&&&&&&&&& &xsd:sequence$>$ &&&&&&&&&&&&&&&&&&&&&&& &xsd:element maxOccurs="1" minOccurs="1" name="out" nillable="true" type="xsd:string" /$>$ &&&&&&&&&&&&&&&&&&& &/xsd:sequence$>$ &&&&&&&&&&&&&&& &/xsd:complexType$>$ &&&&&&&&&&& &/xsd:element$>$ &&&&&&& &/xsd:schema$>$ &&& &/wsdl:types$>$ &&& &wsdl:message name="sayHelloRequest"$>$ &&&&&&& &wsdl:part name="parameters" element="tns:sayHello"$>$/wsdl:part$>$ &&& &/wsdl:message$>$ &&& &wsdl:message name="sayHelloResponse"$>$ &&&&&&& &wsdl:part name="parameters" element="tns:sayHelloResponse"$>$/wsdl:part$>$ &&& &/wsdl:message$>$ &&& &wsdl:portType name="XFireServerPortType"$>$ &&&&&&& &wsdl:operation name="sayHello"$>$ &&&&&&&&&&& &wsdl:input name="sayHelloRequest" message="tns:sayHelloRequest"$>$ &&&&&&&&&&& &/wsdl:input$>$ &&&&&&&&&&& &wsdl:output name="sayHelloResponse" message="tns:sayHelloResponse"$>$ &&&&&&&&&&& &/wsdl:output$>$ &&&&&&& &/wsdl:operation$>$ &&& &/wsdl:portType$>$ &&& &wsdl:binding name="XFireServerHttpBinding" type="tns:XFireServerPortType"$>$ &&&&&&& &wsdlsoap:binding
mce_ transport="" /$>$ &&&&&&& &wsdl:operation name="sayHello"$>$ &&&&&&&&&&& &wsdlsoap:operation soapAction="" /$>$ &&&&&&&&&&& &wsdl:input name="sayHelloRequest"$>$ &&&&&&&&&&&&&&& &wsdlsoap:body use="literal" /$>$ &&&&&&&&&&& &/wsdl:input$>$ &&&&&&&&&&& &wsdl:output name="sayHelloResponse"$>$ &&&&&&&&&&&&&&& &wsdlsoap:body use="literal" /$>$ &&&&&&&&&&& &/wsdl:output$>$ &&&&&&& &/wsdl:operation$>$ &&& &/wsdl:binding$>$ &&& &wsdl:service name="XFireServer"$>$ &&&&&&& &wsdl:port name="XFireServerHttpPort" binding="tns:XFireServerHttpBinding"$>$ &&&&&&&&&&& &wsdlsoap:address location="" /$>$ &&&&&&& &/wsdl:port$>$ &&& &/wsdl:service$>$ &/wsdl:definitions&
本问题标题:
本问题地址:
温馨提示:本问题已经关闭,不能解答。
暂无合适的专家
&&&&&&&&&&&&&&&
希赛网 版权所有 & &&有关java Web开发服务器端与客户端通信的问题_百度知道
有关java Web开发服务器端与客户端通信的问题
问题如下?希望大家能帮助我;客户端通过URL访问服务器端的jsp,谢谢,并将结果返回给客户端,并使用json来封装参数:服务器端如何从jsp到ActionServlet我编写的Web服务器端jsp和ActionServlet(继承HttpServlet)是分离的
使得ActionServlet的HttpServletResponse返回到客户端.客户端发送request到服务器端2,在处理完后?谢谢大家.那jsp起到了什么作用!过程我还是不太明白,使用HttpServletResponse来返回处理结果3,jsp在这里应该做些什么使得客户端对URL(jsp)的访问成为对ActionServlet的执行:1.在ActionServlet中已有HttpServletRequest的getParameter方法来读取客户端发送的参数首先感谢大家的回答
提问者采纳
?用Ajax或者form提交不就行了servlet到jsp,结果),response.href=&#39。。.getAttribute(&quot. jsp就是servlet啊 jsp比servlet的优点就是能够直接像编辑html文件一样写html代码?我说了ajax 或 form提交?转发,将servlet的响应response转发给jsp,jsp中&#39。你是说怎么用jsp访问servlet吗.setAttribute(&quot。;&quot。;),不必再servlet里组织html;&#39jsp到servlet
我知道jsp就是扩展的Servlet,可以做Servlet所做的事,但我现在的Action是写在java的Servlet中,导致我不知道该怎么写JSP。。。在jsp中直接使用window.location.href=&..../ActionServlet&将客户端的请求传送给ActionServlet吗?谢谢!
1. &form action=&&%= pageContext.request.getContext() %&/login&&&/form&servlet配置:&servlet&
&servlet-name&&/servlet-name&
&servlet-class&&/...
&/servlet&
&servlet-mapping&
&servlet-name&&/...........
&url-pattern&login&/..........
&/....2.&button onclick=&login&/&
function login() {
// XMLHttpRequest 的值是否不是undefined
if(typeof XMLHttpRequest != &undefined&) { req = new XMLHttpRequest();
} else { // ie req = new ActiveXObject(&Microsoft.XMLHttp&);
req.onreadystatechange = function() {
if(req.readyState == 4) {
if(req.status == 200) {
req.open(&GET&,&CityServlet?id=&+id, true);
req.send(null); }
额!!! 用jquery吧 有封装好的,你百度下,老久不用想不起来了
感谢你的回答!第一个是简单的直接将访问的请求交给login Servlet来处理第二个是由jsp完成对请求的处理是不是?谢谢!
提问者评价
感谢大家在百忙之中,帮我解决问题,谢谢大家,特别是ruian891015。
其他类似问题
为您推荐:
您可能关注的推广
web开发的相关知识
其他2条回答
用jquery就可以啊,如不用jqeuery,只能写js函数控制了
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁君,已阅读到文档的结尾了呢~~
基于WebServices的高考服务系统的设计和开发,来自著名期刊收费论文。
扫扫二维码,随身浏览文档
手机或平板扫扫即可继续访问
基于WebServices的高考服务系统的设计和开发
举报该文档为侵权文档。
举报该文档含有违规或不良信息。
反馈该文档无法正常浏览。
举报该文档为重复文档。
推荐理由:
将文档分享至:
分享完整地址
文档地址:
粘贴到BBS或博客
flash地址:
支持嵌入FLASH地址的网站使用
html代码:
&embed src='/DocinViewer-4.swf' width='100%' height='600' type=application/x-shockwave-flash ALLOWFULLSCREEN='true' ALLOWSCRIPTACCESS='always'&&/embed&
450px*300px480px*400px650px*490px
支持嵌入HTML代码的网站使用
您的内容已经提交成功
您所提交的内容需要审核后才能发布,请您等待!
3秒自动关闭窗口WebServices入门-.NET教程,Web Service开发-虚拟主机资讯|虚拟主机动态
产品服务快速通道
----------------
==域名注册==
英文域名注册
中文域名注册
==网站推广==
==虚拟主机==
----------------
双线路虚拟主机
基本型虚拟主机
商用型虚拟主机
论坛型虚拟主机
功能型虚拟主机
Vip合租虚拟主机
虚拟主机性能对比
虚拟主机免费试用
机房速度测试
----------------
==租用托管==
服务器租用
----------------
==企业邮局==
购买企业邮局
----------------
==付款方式==
----------------
==联系我们==
您当前位置:->-> ->
WebServices入门-.NET教程,Web Service开发
作者:网友供稿
  西部数码-全国虚拟主机10强!20余项管理功能,全国领先!第6代双线路虚拟主机,南北访问畅通无阻!可在线rar解压,自动数据恢复设置虚拟目录等.免费赠送访问统计,企业邮局.Cn域名注册10元/年,480元起,免费试用7天,满意再付款!P4主机租用799元/月.月付免压金!
文章页数:&
[pre]webservices入门
――理论篇
瑞联科技(中国)有限公司
李春林[/pre]
本文档是用ctrl+c -& ctrl+v产生出来的入门级文档,主要是想说明什么是webservices,webservices的架构,以及几个相关的xml文档。由于小弟知识及技术非常有限,文中不妥之处请各位兄台指正,小弟在此谢过啦。
什么是webservices?
从表面上看:webservices 就是一个应用程序,它向外界暴露出一个能够通过web进行调用的api。这就是说,你能够用编程的方法通过web来调用这个应用程序。我们把调用这个webservices 的应用程序叫做客户。
更专业的描述如下:webservices是描述一些操作(利用标准化的 xml 消息传递机制可以通过网络访问这些操作)的接口。webservices是用标准的、规范的 xml 概念描述的,称为 webservices的服务描述。这一描述囊括了与服务交互需要的全部细节,包括消息格式(详细描述操作)、传输协议和位置。该接口隐藏了实现服务的细节,允许独立于实现服务基于的硬件或软件平台和编写服务所用的编程语言使用服务。这允许并支持基于 webservices的应用程序成为松散耦合、面向组件和跨技术实现。webservices履行一项特定的任务或一组任务。webservices可以单独或同其它 webservices一起用于实现复杂的聚集或商业交易,以及企业集成(eai)。
webservices模型
webservices体系结构基于三种角色(服务提供者、服务注册中心和服务请求者)之间的交互。交互涉及发布、查找和绑定操作。这些角色和操作一起作用于 webservices构件:
webservices软件模块及其描述。在典型(并非 非典^_^)情况下,服务提供者托管可通过网络访问的软件模块(webservices的一个实现)。服务提供者定义 web 服务的服务描述并把它发布到服务请求者或服务注册中心。服务请求者使用查找操作来从本地或服务注册中心检索服务描述,然后使用服务描述与服务提供者进行绑定并调用 web 服务实现或同它交互。服务提供者和服务请求者角色是逻辑结构,因而服务可以表现两种特性。下图 图示了这些操作、提供这些操作的组件及它们之间的交互。
webservices协议栈
要以一种可互操作的方式执行发布、发现和绑定这三个操作,必须有一个包含每一层标准的 webservices协议栈。下图展示了一个概念性 webservices协议栈。上面的几层建立在下面几层提供的功能之上。垂直的条表示在协议栈中每一层必须满足的需求。左面的文本表示协议栈的那一层所应用的标准技术。
下面对上面是概念性的协议栈中,的每一层做一个粗糙的说明:
第一层(network):这一层的这些协议都是现在运用比较广泛的协议啦,现在http运用的最多啦,好处是显而易见的,其他的我就不多说了吧。(主要我怕我说出来会错误百出,被大家嘲笑。 *_*)。
第二层(xml-based messaging)这一层中主要体现怎么去调用webservices。现在运用比较广泛的主要有两种,一种是xml-rpc(xml-remote procedure call), 另一种是soap(simple object access protocal)。相比之下soap比xml-rpc有一定的优势:soap在处理复杂数据(如数组等)要比xml-rpc更容易一些;xml-rpc没有标准化错误代码;下面我们着重看看soap:
什么是soap?
对soap的一种简单理解:
soap是一种xml application,soap简单的理解,就是这样的一个开放协议soap=rpc+http+xml:采用http作为底层通讯协议;rpc作为一致性的调用途径,xml作为数据传送的格式,允许服务提供者和服务客户经过防火墙在internet进行通讯交互。如下图:
对soap更深一步的理解:
soap简单对象访问协议是在分散或分布式的环境中交换信息的简单的协议,是一个基于xml的协议,它包括四个部分:soap封装(envelop),封装定义了一个描述消息中的内容是什么,是谁发送的,谁应当接受并处理它以及如何处理它们的框架,如下图;soap编码规则(encoding rules),用于表示应用程序需要使用的数据类型的实例,一般遵循xmlschema(定义了一系列的简单数据类型)规范; soap rpc表示(rpc representation),表示远程过程调用和应答的协定;soap绑定(binding),使用底层协议交换信息。虽然这四个部分都作为soap的一部分,作为一个整体定义的,但他们在功能上是相交的、彼此独立的。特别的,信封和编码规则是被定义在不同的xml命名空间(namespace)中,这样使得定义更加简单。
图:soap封装(envelop)
下面让我们来看一个soap的例子:
[pre]post /calendar-request http/1.1
host: .cn
content-type: text/ charset=&utf-8&
content-length: 507
soapaction:””
&soapenv:envelope xmlns:soapenv=&http://schemas.xmlsoap.org/soap/envelope/&
xmlns:xsd=&http://www.w3.org/2001/xmlschema& xmlns:xsi=&http://www.w3.org/2001/xmlschema-instance&&
&soapenv:body&
&ns1:searchpaynoteresponse
soapenv:encodingstyle=&http://schemas.xmlsoap.org/soap/encoding/&
xmlns:ns1=&http://external.charge.&&
&searchpaynotereturn href=&#id0&/&
&/ns1:searchpaynoteresponse&
&multiref id=&id0& soapenc:root=&0& soapenv:encodingstyle=&http://schemas.xmlsoap.org/soap/encoding/&
xsi:type=&ns2:externalpaynotevo&
xmlns:soapenc=&http://schemas.xmlsoap.org/soap/encoding/&
xmlns:ns2=&http://vo.charge.&&
&paynoteno xsi:type=&xsd:string&&4&/paynoteno&
&startdate xsi:type=&xsd:string& xsi:nil=&true&/&
&disaid xsi:type=&xsd:string& xsi:nil=&true&/&
&annotation xsi:type=&xsd:string& xsi:nil=&true&/&
&chargeitemno3 xsi:type=&xsd:string& xsi:nil=&true&/&
&amount xsi:type=&xsd:double&&0.0&/amount&
&chargeitemno2 xsi:type=&xsd:string& xsi:nil=&true&/&
&loginkey xsi:type=&xsd:string&&ycptewkew&/loginkey&
&chargeitemno1 xsi:type=&xsd:string& xsi:nil=&true&/&
&usersign xsi:type=&xsd:string& xsi:nil=&true&/&
&operator xsi:type=&xsd:string& xsi:nil=&true&/&
&usercert xsi:type=&xsd:string& xsi:nil=&true&/&
&quantity3 xsi:type=&xsd:double&&0.0&/quantity3&
&quantity2 xsi:type=&xsd:double&&0.0&/quantity2&
&unitname xsi:type=&xsd:string& xsi:nil=&true&/&
&srvsign xsi:type=&xsd:string& xsi:nil=&true&/&
&quantity1 xsi:type=&xsd:double&&0.0&/quantity1&
&srvcert xsi:type=&xsd:string& xsi:nil=&true&/&
&externalpaynoteno xsi:type=&xsd:string& xsi:nil=&true&/&
&status xsi:type=&xsd:int&&1&/status&
&randstr xsi:type=&xsd:string& xsi:nil=&true&/&
&returncode xsi:type=&xsd:int&&0&/returncode&
&enddate xsi:type=&xsd:string& xsi:nil=&true&/&
&price3 xsi:type=&xsd:double&&0.0&/price3&
&price2 xsi:type=&xsd:double&&0.0&/price2&
&price1 xsi:type=&xsd:double&&0.0&/price1&
&unitno xsi:type=&xsd:string& xsi:nil=&true&/&
&payername xsi:type=&xsd:string& xsi:nil=&true&/&
&/multiref&
&/soapenv:body&
&/soapenv:envelope&[/pre]
第三层(service description):在这一层中主要是我们服务的描述,向客户端说明我们的服务,告诉客户端、我们的提供了什么样的接口可供调用(what),怎么样去调用(how),到那去调用(where)。在这一层中主要的协议是wsdl(web services description language)。wsdl 是一种xml application,它的作用就是给客户端描述我们接口的what,how,where,也就是说:wsdl 服务定义为分布式系统提供了可机器识别的sdk文档,并且可用于描述自动执行应用程序通信中所涉及的细节。
wsdl 文档将web服务定义为服务访问点或端口的集合。在 wsdl 中,由于服务访问点和消息的抽象定义已从具体的服务部署或数据格式绑定中分离出来,因此可以对抽象定义进行再次使用:消息,指对交换数据的抽象描述;而端口类型,指操作的抽象集合。用于特定端口类型的具体协议和数据格式规范构成了可以再次使用的绑定。将web访问地址与可再次使用的绑定相关联,可以定义一个端口,而端口的集合则定义为服务。因此,wsdl 文档在web服务的定义中使用下列元素:
•
types - 数据类型定义的容器,它使用某种类型系统(一般地使用xml schema中的类型系统)。
message - 通信消息的数据结构的抽象类型化定义。使用types所定义的类型来定义整个消息的数据结构。
operation - 对服务中所支持的操作的抽象描述,一般单个operation描述了一个访问入口的请求/响应消息对。
porttype - 对于某个访问入口点类型所支持的操作的抽象集合,这些操作可以由一个或多个服务访问点来支持。
binding - 特定端口类型的具体协议和数据格式规范的绑定。
port - 定义为协议/数据格式绑定与具体web访问地址组合的单个服务访问点。
service - 相关服务访问点的集合。
我们可以参考下图,来理解一下wsdl文档的结构组织:
说明:其中,
types是一个数据类型定义的容器,包含了所有在消息定义中需要的xml元素的类型定义,它一般遵循xmlschema的规范。
message具体定义了在通信中使用的消息的数据结构,message元素包含了一组part元素,每个part元素都是最终消息的一个组成部分,每个part都会引用一个datatype来表示它的结构。part元素不支持嵌套(可以使用datatype来完成这方面的需要),都是并列出现。
porttype具体定义了一种服务访问入口的类型,何谓访问入口的类型呢?就是传入/传出消息的模式及其格式。一个porttype可以包含若干个operation,而一个operation则是指访问入口支持的一种类型的调用。在wsdl里面支持四种访问入口调用的模式:
1.
请求/响应;
响应/请求。
service描述的是一个具体的被部署的web服务所提供的所有访问入口的部署细节,一个service往往会包含多个服务访问入口,而每个访问入口都会使用一个port元素来描述。
port描述的是一个服务访问入口的部署细节,包括通过哪个web地址(url)来访问,应当使用怎样的消息调用模式来访问等。其中消息调用模式则是使用binding结构来表示。
binding结构定义了某个porttype与某一种具体的网络传输协议或消息传输协议相绑定,从这一层次开始,描述的内容就与具体服务的部署相关了。比如可以将porttype与soap/http绑定,也可以将porttype与mime/smtp相绑定等。
下面我们给出一个wsdl的文档实例:
[pre]&?xml version=&1.0& encoding=&utf-8&?&
&wsdl:definitions targetnamespace=&http://external.charge.&
xmlns=&http://schemas.xmlsoap.org/wsdl/&
xmlns:apachesoap=&http://xml.apache.org/xml-soap&
xmlns:impl=&http://external.charge.-impl&
xmlns:intf=&http://external.charge.&
xmlns:soapenc=&http://schemas.xmlsoap.org/soap/encoding/&
xmlns:tns2=&http://vo.charge.&
xmlns:wsdl=&http://schemas.xmlsoap.org/wsdl/&
xmlns:wsdlsoap=&http://schemas.xmlsoap.org/wsdl/soap/&
xmlns:xsd=&http://www.w3.org/2001/xmlschema&&
&wsdl:types&
&schema targetnamespace=&http://vo.charge.&
xmlns=&http://www.w3.org/2001/xmlschema&&
&import namespace=&http://schemas.xmlsoap.org/soap/encoding/&/&
&complextype name=&externalpaynotevo&&
&sequence&
&element name=&amount& type=&xsd:double&/&
&element name=&annotation& nillable=&true& type=&xsd:string&/&
&element name=&chargeitemno1& nillable=&true& type=&xsd:string&/&
&element name=&chargeitemno2& nillable=&true& type=&xsd:string&/&
&element name=&chargeitemno3& nillable=&true& type=&xsd:string&/&
&element name=&disaid& nillable=&true& type=&xsd:string&/&
&element name=&enddate& nillable=&true& type=&xsd:string&/&
&element name=&externalpaynoteno& nillable=&true& type=&xsd:string&/&
&element name=&loginkey& nillable=&true& type=&xsd:string&/&
&element name=&operator& nillable=&true& type=&xsd:string&/&
&element name=&payername& nillable=&true& type=&xsd:string&/&
&element name=&paynoteno& nillable=&true& type=&xsd:string&/&
&element name=&price1& type=&xsd:double&/&
&element name=&price2& type=&xsd:double&/&
&element name=&price3& type=&xsd:double&/&
&element name=&quantity1& type=&xsd:double&/&
&element name=&quantity2& type=&xsd:double&/&
&element name=&quantity3& type=&xsd:double&/&
&element name=&randstr& nillable=&true& type=&xsd:string&/&
&element name=&returncode& type=&xsd:int&/&
&element name=&srvcert& nillable=&true& type=&xsd:string&/&
&element name=&srvsign& nillable=&true& type=&xsd:string&/&
&element name=&startdate& nillable=&true& type=&xsd:string&/&
&element name=&status& type=&xsd:int&/&
&element name=&unitno& nillable=&true& type=&xsd:string&/&
&element name=&unitname& nillable=&true& type=&xsd:string&/&
&element name=&usercert& nillable=&true& type=&xsd:string&/&
&element name=&usersign& nillable=&true& type=&xsd:string&/&
&/sequence&
&/complextype&
&element name=&externalpaynotevo& nillable=&true& type=&tns2:externalpaynotevo&/&
&/wsdl:types&
&wsdl:message name=&logoutrequest&&
&wsdl:part name=&epnvo& type=&tns2:externalpaynotevo&/&
&/wsdl:message&
&wsdl:message name=&searchpaynoteresponse&&
&wsdl:part name=&searchpaynotereturn& type=&tns2:externalpaynotevo&/&
&/wsdl:message&
&wsdl:message name=&searchpaynoterequest&&
&wsdl:part name=&epnvo& type=&tns2:externalpaynotevo&/&
&/wsdl:message&
&wsdl:message name=&genpaynoteresponse&&
&wsdl:part name=&genpaynotereturn& type=&tns2:externalpaynotevo&/&
&/wsdl:message&
&wsdl:message name=&loginresponse&&
&wsdl:part name=&loginreturn& type=&tns2:externalpaynotevo&/&
&/wsdl:message&
&wsdl:message name=&logoutresponse&&
&wsdl:part name=&logoutreturn& type=&tns2:externalpaynotevo&/&
&/wsdl:message&
&wsdl:message name=&genpaynoterequest&&
&wsdl:part name=&epvo& type=&tns2:externalpaynotevo&/&
&/wsdl:message&
&wsdl:message name=&loginrequest&&
&wsdl:part name=&epnvo& type=&tns2:externalpaynotevo&/&
&/wsdl:message&
&wsdl:porttype name=&externalinterface&&
&wsdl:operation name=&login& parameterorder=&epnvo&&
&wsdl:input message=&intf:loginrequest& name=&loginrequest&/&
&wsdl:output message=&intf:loginresponse& name=&loginresponse&/&
&/wsdl:operation&
&wsdl:operation name=&logout& parameterorder=&epnvo&&
&wsdl:input message=&intf:logoutrequest& name=&logoutrequest&/&
&wsdl:output message=&intf:logoutresponse& name=&logoutresponse&/&
&/wsdl:operation&
&wsdl:operation name=&genpaynote& parameterorder=&epvo&&
&wsdl:input message=&intf:genpaynoterequest&
name=&genpaynoterequest&/&
&wsdl:output message=&intf:genpaynoteresponse&
name=&genpaynoteresponse&/&
&/wsdl:operation&
&wsdl:operation name=&searchpaynote& parameterorder=&epnvo&&
&wsdl:input message=&intf:searchpaynoterequest&
name=&searchpaynoterequest&/&
&wsdl:output message=&intf:searchpaynoteresponse&
name=&searchpaynoteresponse&/&
&/wsdl:operation&
&/wsdl:porttype&
&wsdl:binding name=&externalinterfacesoapbinding&
type=&intf:externalinterface&&
&wsdlsoap:binding style=&rpc&
transport=&http://schemas.xmlsoap.org/soap/http&/&
&wsdl:operation name=&login&&
&wsdlsoap:operation soapaction=&&/&
&wsdl:input name=&loginrequest&&
&wsdlsoap:body
encodingstyle=&http://schemas.xmlsoap.org/soap/encoding/&
namespace=&http://external.charge.& use=&encoded&/&
&/wsdl:input&
&wsdl:output name=&loginresponse&&
&wsdlsoap:body
encodingstyle=&http://schemas.xmlsoap.org/soap/encoding/&
namespace=&http://external.charge.& use=&encoded&/&
&/wsdl:output&
&/wsdl:operation&
&wsdl:operation name=&logout&&
&wsdlsoap:operation soapaction=&&/&
&wsdl:input name=&logoutrequest&&
&wsdlsoap:body encodingstyle=&http://schemas.xmlsoap.org/soap/encoding/&
namespace=&http://external.charge.& use=&encoded&/&
&/wsdl:input&
&wsdl:output name=&logoutresponse&&
&wsdlsoap:body encodingstyle=&http://schemas.xmlsoap.org/soap/encoding/&
namespace=&http://external.charge.& use=&encoded&/&
&/wsdl:output&
&/wsdl:operation&
&wsdl:operation name=&genpaynote&&
&wsdlsoap:operation soapaction=&&/&
&wsdl:input name=&genpaynoterequest&&
&wsdlsoap:body encodingstyle=&http://schemas.xmlsoap.org/soap/encoding/&
namespace=&http://external.charge.& use=&encoded&/&
&/wsdl:input&
&wsdl:output name=&genpaynoteresponse&&
&wsdlsoap:body encodingstyle=&http://schemas.xmlsoap.org/soap/encoding/&
namespace=&http://external.charge.& use=&encoded&/&
&/wsdl:output&
&/wsdl:operation&
&wsdl:operation name=&searchpaynote&&
&wsdlsoap:operation soapaction=&&/&
&wsdl:input name=&searchpaynoterequest&&
&wsdlsoap:body encodingstyle=&http://schemas.xmlsoap.org/soap/encoding/&
namespace=&http://external.charge.& use=&encoded&/&
&/wsdl:input&
&wsdl:output name=&searchpaynoteresponse&&
&wsdlsoap:body encodingstyle=&http://schemas.xmlsoap.org/soap/encoding/&
namespace=&http://external.charge.& use=&encoded&/&
&/wsdl:output&
&/wsdl:operation&
&/wsdl:binding&
&wsdl:service name=&externalinterfaceservice&&
&wsdl:port binding=&intf:externalinterfacesoapbinding& name=&externalinterface&&
&wsdlsoap:address location=&http://localhost:7001/gfmis/services/externalinterface&/&
&/wsdl:port&
&/wsdl:service&
&/wsdl:definitions&[/pre]
第四层(service publication):
第五层(service discovery):这两层都是关于uddi的协议,我们暂时用不上,现在也暂时没有,以后补上(^_^)。
文章整理:西部数码--专业提供、服务
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!
文章页数:&
??????????
??????????
版权申明:本站文章均来自网络,如有侵权,请联系我们,我们收到后立即删除,谢谢!
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有。
版权所有 西部数码()
CopyRight (c) 2002~ all right reserved.
公司地址:四川省成都市金牛区一环路北一段99号环球广场24楼 邮编:610031
电话总机:028-08 38
售前咨询:总机转201 202 203 204 206 208
售后服务:总机转211 212 213 214
财务咨询:总机转224 223 传真:028- 财务QQ:
售前咨询QQ:2182518
售后服务QQ:}

我要回帖

更多关于 extjs webservices 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信