开发环境: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. Windows下使用WinRAR命令自动备份文件

    最近有一个需求:为了防止数据丢失,每天对固定文件夹下的文件进行打包压缩备份. 解决办法:使用Windows的任务计划程序,每天执行一下压缩命令: Windows任务计划程序在这里就不再介绍了,网上有很 ...

  2. [linux] vim在源代码中自动添加作者信息(转载)

    原文出处: http://www.vimer.cn/2009/10/用vim在源代码中添加你的个人信息.html vim ~/.vimrc "进行版权声明的设置 "添加或更新头 m ...

  3. Linux学习——操作文件与目录

    1. ls:列出文件及目录信息. 命令格式:ls [选项] ... 常用选项: -a 显示指定目录下所有子目录与文件,包括隐藏文件. -A 显示指定目录下所有子目录与文件,包括隐藏文件.但不列出“.” ...

  4. GCD最大公约数

    说明: 最初跟鹏哥学习最大公约数的算法是辗转相除,确实印象很深刻,那种辗转赋值的思想在好多题目中都有运用,但随着进一步学习,我也参考了其他几种方便快捷的最大公约数求法,在这里做一个总结. . int ...

  5. "Hello World"团队召开的第三周第六次会议

    今天是我们团队“Hello World!”团队召开的第三周的第六次会议.博客内容: 一.会议时间 二.会议地点 三.会议成员 四.会议内容 五.todo list 六.会议照片 七.燃尽图 一.会议时 ...

  6. 【探路者】Alpha发布用户使用报告

    预期统计用户使用数量:13人. 博文内容:1用户列表.2评论列表.3统计与总结 1用户列表: 二.评论内容 用户1:1不够好看.2不应该是中国地图为背景,蛇头是人物头像的么?(那是宣传片,不是预览图) ...

  7. wamp上能够访问jsp(未解决 游客勿看)

    Windows下使用apache的jk_mod连接WAMP和Tomcat 发表于 2013 年 4 月 29 日 由 www.tonitech.com的站长 | 暂无评论 | Apache,Windo ...

  8. linshi12

    #include<iostream> using namespace std; int main(){ int a[50]; a[1]=5; int i; for(i=2;;i++){ a ...

  9. 周总结<4>

    经过了一周的学习,我们在html以及C语言方面又有的新的知识点的学习. html 自习表格,函数等 C语言 哈弗曼编码 Html案例: 一. <!DOCTYPE html PUBLIC &quo ...

  10. lintcode-419-罗马数字转整数

    419-罗马数字转整数 给定一个罗马数字,将其转换成整数. 返回的结果要求在1到3999的范围内. 说明 什么是 罗马数字? https://en.wikipedia.org/wiki/Roman_n ...