开发环境: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. php爬虫学习笔记1 PHP Simple HTML DOM Parser

    常用爬虫. 0. Snoopy是什么? (下载snoopy)   Snoopy是一个php类,用来模仿web浏览器的功能,它能完成获取网页内容和发送表单的任务.   Snoopy的一些特点:   * ...

  2. redis 学习记录

    http://www.yiibai.com/redis/redis_quick_guide.html Redis 是一款依据BSD开源协议发行的高性能Key-Value存储系统(cache and s ...

  3. 寻找bug

    bug1:void不应有返回值. bug2:while(n--)没有条件终止循环. bug3:size和data没有定义 bug4:arr 是sz 在大于0的情况下创建的 一定部位bull   下面的 ...

  4. (Miller Rabin算法)判断一个数是否为素数

    1.约定 x%y为x取模y,即x除以y所得的余数,当x<y时,x%y=x,所有取模的运算对象都为整数. x^y表示x的y次方.乘方运算的优先级高于乘除和取模,加减的优先级最低. 见到x^y/z这 ...

  5. OSG学习:阴影代码示例

    效果图: 代码示例: #include <osgViewer/Viewer> #include <osg/Node> #include <osg/Geode> #i ...

  6. Java包名命名规则(转载)

    转载自:http://lilinhai548.blog.163.com/blog/static/5847332920155132151359/ 鸣谢原作者  学习Java的童鞋们都知道,Java的包. ...

  7. 【beta】Scrum站立会议第6次....11.8

    小组名称:nice! 组长:李权 成员:于淼  刘芳芳韩媛媛 宫丽君 项目内容:约跑app(约吧) 时间:2016.11.8    12:00——12:30 地点:传媒西楼220室 本次对beta阶段 ...

  8. VSVC2010中常用的C++11特性

    static_assert 声明 static_assert 声明在编译时测试软件断言,这与在运行时进行测试的其他断言机制不同. 如果断言失败,则编译也将失败,且系统将发出指定的错误消息. const ...

  9. mysql有索引和无索引的查询速度对比

    演示100万级数据有索引和无索引的情况下的查找速度:

  10. 【uoj#174】新年的破栈 贪心

    题目描述 给你一个长度为 $n$ 的序列和一个空的双端队列,每次进行3种操作种的一种: 1.将序列中编号最小的数加入到双端队列的队尾:2.从双端队列的队尾取出一个数:3.从双端队列的队头取出一个数. ...