刚到新公司,发现项目中有webservice的调用,而且不少,正好趁此机会学习一下。
下面是一个简单的例子,利用MyEclipse自动生成了很多文件,因此深入的话可能不是那么了解,不过先对webservice有个大致的认识吧。
How to?
step 1
New a WebService Project
give a project name
choose Framework as XFire
warning
If we choose the j2ee5.0 for specification.The tomcat5 must not be used.
Because of jars conflict.
click next to project library configuration
select nothing in the area.we have to download a new version XFire jar for our project.
put jar in the 'lib' folder.remember to config the classPath.
now.create packages and create interface.of course.some methods should be created in this interface.
next.create a class to implement the interface above.
finish your method in the class.
new a webService for this project
select 'create web service from java bean' for strategy
click next
give a name to the web service.Be sure the path of interface and the path of imolement class are correctly.
then finish the config.
Let's have a try
http://127.0.0.1:8080/<projectName>/services/<WebServiceName>?wsdl
If we see the content like xml file in our exploror.
congratulations we have finished the step 1.
What is wsdl?
| |
Web Service Describe Language.
step 2
Create a java project .
create packages for java files...
new a web service client for this project.
select 'SW-JAX' for framework.
write 'http://127.0.0.1:8080/<projectName>/services/<WebServiceName>?wsdl'in to the WSDL URL textarea.
put the path of the package we've created into the 'Package' textarea.
click next .after testing...finish.
If no errors.we could create a class with a main method.
and write :
MyEclipse will create some class flies autoly...
<WebServiceName>PortType service = new <WebServiceName> ().get<WebServiceName>HttpPort();
then we can use the 'service' we created to call any method in the web service project above.
以上纯手写,肯定有不对的地方,估计就自己能看懂。
web service 其实就是一个跨语言,跨平台,跨各种的交流通道,A是C#项目,B是java项目,A想要调用B中的方法,那么B先创造WS所需要的条件,暴露出可以供A调用的接口,A通过WSClient调用B所暴露给自己的接口即实现了调用B项目中的方法。不同的语言怎么能相互调用?大家交流的关键就是xml文件。说的低俗点就是有一个叫xml的翻译会各国语言,通过他,几个只会本国语言的老头谈天说地。
当然执行这个并非随意之事,WS是遵守着规范的。
分享到:
相关推荐
webservice小例子 用于webservice 接口开发,客户端调用
webservice 小例子 myeclipse 部署即可用
webService小例子,欢迎下载
.net调用webservice接口例子.net调用webservice接口例子.net调用webservice接口例子.net调用webservice接口例子
websercice,这段代码来至有10多年编程经验的工程师的编写,能帮初学者,请大家来下载吧,
C#webservice应用例子(含头验证) 其中包含详细的源代码和注释说明
webservice简单例子,使用Axis1框架,包括客户端和服务端例子,部署在tomcat运行
webservice的简单例子
webservice接口例子 八优网提供
一个基于xfire开发的Webservice小例子,初学者可以看看!
一个基于axis的webservice接口例子
NULL 博文链接:https://zhouyangchenrui.iteye.com/blog/427328
Axis2 Webservice端例子Axis2 Webservice端例子
webservice详细例子,详细请看: jax-ws 与 spring的整合(下) http://poshidi.com/jax-ws-spring2
创建一个很简单的WEBSERVICE,新手可以看看
XFire_WebService开发例子.zip XFire_WebService开发例子.zip XFire_WebService开发例子.zip