开发环境:myeclipse8.6+jdk1.6.0_29+tomcat6.0.37

JAX-WS搭建webservice:http://www.cnblogs.com/gavinYang/p/3525287.html

一、搭建WebService

1.新建一个Web Service Project



做完上述步骤后会发现项目中多了一个WebServices目录和WebServices目录下services.xml文件,web.xml会多一个Servlet配置
指明了当遇到/services/*请求时,将选用XFireConfigurableServlet来处理

2.New Web Service


做完上述步骤后会发现WebServices目录下services.xml文件多了如下内容

src目录下自动生成了两个类(我们也可以写上自己的接口方法)
UserServiceImpl.java

package com.ws.test;
//Generated by MyEclipse public class UserServiceImpl implements IUserService { public String example(String message) {
return message;
} }

IUserService.java

package com.ws.test;
//Generated by MyEclipse public interface IUserService { public String example(String message); }

3.部署项目到tomcat,访问url:http://localhost:8080/ws/services/UserService?wsdl

  <?xml version="1.0" encoding="UTF-8" ?>
- <wsdl:definitions targetNamespace="http://test.ws.com" xmlns:soapenc12="http://www.w3.org/2003/05/soap-encoding" xmlns:tns="http://test.ws.com" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap11="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc11="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
- <wsdl:types>
- <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://test.ws.com">
- <xsd:element name="example">
- <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="exampleResponse">
- <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="exampleRequest">
<wsdl:part name="parameters" element="tns:example" />
</wsdl:message>
- <wsdl:message name="exampleResponse">
<wsdl:part name="parameters" element="tns:exampleResponse" />
</wsdl:message>
- <wsdl:portType name="UserServicePortType">
- <wsdl:operation name="example">
<wsdl:input name="exampleRequest" message="tns:exampleRequest" />
<wsdl:output name="exampleResponse" message="tns:exampleResponse" />
</wsdl:operation>
</wsdl:portType>
- <wsdl:binding name="UserServiceHttpBinding" type="tns:UserServicePortType">
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
- <wsdl:operation name="example">
<wsdlsoap:operation soapAction="" />
- <wsdl:input name="exampleRequest">
<wsdlsoap:body use="literal" />
</wsdl:input>
- <wsdl:output name="exampleResponse">
<wsdlsoap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
- <wsdl:service name="UserService">
- <wsdl:port name="UserServiceHttpPort" binding="tns:UserServiceHttpBinding">
<wsdlsoap:address location="http://localhost:8080/ws/services/UserService" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

二、调用WebServices
1.新建一个Java Project

2.添加XFire类库至构建路径

3.我们新建一个Java类来测试调用webservice

package com.wsc.test;

import java.net.URL;

import org.codehaus.xfire.client.Client;

public class TestWs {

    public static void main(String[] args) {
try{
Client client = new Client(new URL("http://localhost:8080/ws/services/UserService?wsdl"));
Object[] results = client.invoke("example", new Object[] {"Gavin"});
System.out.println((String) results[0]);
}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
}

输出结果为:Gavin

XFire搭建WebService和客户端访问程序的更多相关文章

  1. JAX-WS搭建WebService和客户端访问程序

    开发环境:myeclipse8.6+jdk1.6.0_29+tomcat6.0.37 XFire搭建webservice: http://www.cnblogs.com/gavinYang/p/352 ...

  2. Linux Samba目录服务搭建与Java客户端访问

    前言: 本文比较简略,只求快速入门,若要了解详情,推荐一篇文章:http://www.cnblogs.com/mchina/archive/2012/12/18/2816717.html 1,安装sa ...

  3. 使用xfire搭建webService服务

    后边有个项目需要接入4A,要用到webService服务,暂时还不确定是不是会有我的事,但为了有备无患,还是抽时间学习了以下相关的知识. 本来我所了解到的发布webService服务有用cxf和xfi ...

  4. C++客户端访问WebService VS2008

    VS2008及之后的版本已经不支持使用C++开发WEBService服务了,如果要在VS上开发WEBService,需要使用C#开发语言. 一.gSOAP简介 gSOAP编译工具提供了一个基于SOAP ...

  5. cxf开发webservice服务器+客户端(各种类型的参数传递返回)

    开发环境:eclipse3.7+jdk1.6.0_29+tomcat6.0.37 XFire搭建webservice: http://www.cnblogs.com/gavinYang/p/35253 ...

  6. 搭建QQ聊天通信的程序:(1)基于 networkcomms.net 创建一个WPF聊天客户端服务器应用程序 (1)

    搭建QQ聊天通信的程序:(1)基于 networkcomms.net 创建一个WPF聊天客户端服务器应用程序 原文地址(英文):http://www.networkcomms.net/creating ...

  7. 关于搭建webservice以及无法通过URL访问的简易解决办法

    之前工作天天在用webservice,但是从没有自己独立的搭建一个全新的项目,今天好不容易自己搭了一个webservice,报错不少,记录下来免得以后又忘了. 一.搭建webservice需要做的几点 ...

  8. 问题-XE8客户端访问Webservice时报“no selected dom vendor”

    问题现象:XE8做的客户端访问XE8做的Webservice时,客户端报“no selected dom vendor”. 问题原因:原因不明,应该是用到了XML转换等方法吧.有高手了解的,请M我. ...

  9. centos7 搭建svn服务器&客户端的访问&备份迁移

    当今用于版本控制的软件程序主要的有svn和git,其它软件咱不熟悉,今天记录下搭建svn服务器和svn客户端使用: 使用环境:虚拟机为centos7系统,svn服务器安装在centos7系统平台上,s ...

随机推荐

  1. ubuntu安装和查看已安装软件

    说明:由于图形化界面方法(如Add/Remove... 和Synaptic Package Manageer)比较简单,所以这里主要总结在终端通过命令行方式进行的软件包安装.卸载和删除的方法. 一.U ...

  2. 周总结<2>

    本打算在这周日写周总结的,但由于事情太多,还要组织团日活动,所以没时间写.不过上周主要是一些书本上的学习,但是在周日的时候完成了一款小游戏还是比较有成就感的,但是主要是因为html的考试才去做的. 代 ...

  3. sql nolock是什么

    百度:SQL Server 中的 NOLOCK 到底是什么意思? 文章地址:http://blog.sina.com.cn/s/blog_7d3b18a50100rfwg.html 查询语句加上 no ...

  4. 团队作业4——第一次项目冲刺(Alpha版本)第一次

    一.会议内容 制定任务内容 制作leangoo表格 初步工作 二.各人工作 成员 计划任务 遇见难题 贡献比 塗家瑜(组长) 后端与数据库通讯 无 1 张新磊 表设计 无 1 姚燕彬 测试计划编写 无 ...

  5. lintcode-202-线段树的查询

    202-线段树的查询 对于一个有n个数的整数数组,在对应的线段树中, 根节点所代表的区间为0-n-1, 每个节点有一个额外的属性max,值为该节点所代表的数组区间start到end内的最大值. 为Se ...

  6. lintcode-198-排列序号II

    198-排列序号II 给出一个可能包含重复数字的排列,求这些数字的所有排列按字典序排序后该排列在其中的编号.编号从1开始. 样例 给出排列[1, 4, 2, 2],其编号为3. 思路 和 lintco ...

  7. js中call(),apply(),以及prototype的含义

    最近段时间主要学习前端去了,然而所遇到的一些问题我觉得有必要去深究一下 prototype: 1 js中有三种表达方法 类方法,属性方法,原型方法 function People(name) { th ...

  8. eclipse取消validation验证

    点击按钮如下:window-Preferences-Validation.如图. 然后把build里面的都取消.即可.

  9. Scrum Meeting Beta - 4

    Scrum Meeting Beta - 4 NewTeam 2017/12/2 地点:新主楼F座二楼 任务反馈 团队成员 完成任务 计划任务 安万贺 完成了部分页面标题栏颜色的修改和字体的调整Iss ...

  10. PAT 甲级 1127 ZigZagging on a Tree

    https://pintia.cn/problem-sets/994805342720868352/problems/994805349394006016 Suppose that all the k ...