eclipse开发webservice服务

2023-10-31

eclipse开发webservice服务

开发工具:eclipse4.5.1

操作系统:win7 64bit

web服务器:tomcat7

JDK:1.7.0_79

Maven:3.2.3

 

eclipse开发webservice服务 

 

一、创建web项目

webservice是通过http/https协议访问,所以要创建web项目,这里按maven格式来创建web工程。



  

工程名称:test-axis1,这里使用axis1版本。

IUpayCsysTmallTxnLog.java    webservice的接口

UpayCsysTmallTxnLog.java    接口的实现

UpayCsysTmallTxnLogReq.java接口的请求对象

UpayCsysTmallTxnLogResp.java接口返回对象

 

二、创建webservice服务端

2.1 选中工程test-axis1,右键 New->Other->Web Services->Web Service

 

 
2.2 点击【Next】按钮



 

Web service type下拉框选择:Bottom up java bean Web Service (自底向上的java bean Web服务)

点击Browse,输入框中输入刚才新建的接口实现类,这个类将作为web service的调用服务



 

2.3 点击【OK】,然后再Configuration栏里点击【Server runtime:tomcat……】



 

eclipse需要配置好web服务器,这里用的是tomcat所以选中输入框圈的那部分。

 

2.4 点击【OK】按钮,在弹出来的对话框里点击【Next】



 

2.5 按默认选择即可,点击【Next】



 

2.6 点击【Start server】按钮,测试web service服务端,如果没问题,点击【Next】按钮



 

2.7 按默认配置,一直点击【Next】



  

2.8 点击【Finish】按钮之后,如果不出问题的话,eclipse自动启动web service服务端,并弹出两个自带的浏览器,上面显示一些信息

 

 

eclipse的web service插件会帮生成很多东西,比如jar包,wsdd文件,wsdl文件等等其他配置信息,如左边圈子里的,都是自动生成的。

如web.xml,会自动写入很多配置信息:

<!DOCTYPE web-app PUBLIC

 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"

 "http://java.sun.com/dtd/web-app_2_3.dtd" >

 

<web-app>

  <display-name>Archetype Created Web Application</display-name>

  <servlet>

          <servlet-name>AxisServlet</servlet-name>

          <display-name>Apache-Axis Servlet</display-name>

          <servlet-class>org.apache.axis.transport.http.AxisServlet</servlet-class>

  </servlet>

  <servlet>

          <servlet-name>AdminServlet</servlet-name>

          <display-name>Axis Admin Servlet</display-name>

          <servlet-class>org.apache.axis.transport.http.AdminServlet</servlet-class>

          <load-on-startup>100</load-on-startup>

  </servlet>

  <servlet-mapping>

          <servlet-name>AxisServlet</servlet-name>

          <url-pattern>/servlet/AxisServlet</url-pattern>

  </servlet-mapping>

  <servlet-mapping>

          <servlet-name>AxisServlet</servlet-name>

          <url-pattern>*.jws</url-pattern>

  </servlet-mapping>

  <servlet-mapping>

          <servlet-name>AxisServlet</servlet-name>

          <url-pattern>/services/*</url-pattern>

  </servlet-mapping>

  <servlet-mapping>

          <servlet-name>AdminServlet</servlet-name>

          <url-pattern>/servlet/AdminServlet</url-pattern>

  </servlet-mapping>

</web-app>

 

2.9 打开test-axis1/src/main/webapp/wsdl/UpayCsysTmallTxnLog.wsdl配置文件,可以看到很多入参和出参的描述信息

<?xml version="1.0" encoding="UTF-8"?>

<wsdl:definitions targetNamespace="http://axis1.webservice.plg.com" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://axis1.webservice.plg.com" xmlns:intf="http://axis1.webservice.plg.com" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<!--WSDL created by Apache Axis version: 1.4

Built on Apr 22, 2006 (06:55:48 PDT)-->

 <wsdl:types>

  <schema elementFormDefault="qualified" targetNamespace="http://axis1.webservice.plg.com" xmlns="http://www.w3.org/2001/XMLSchema">

   <element name="getUpayCsysTmallLog">

    <complexType>

     <sequence>

      <element name="req" type="impl:UpayCsysTmallTxnLogReq"/>

      <element name="version" type="xsd:string"/>

     </sequence>

    </complexType>

   </element>

   <complexType name="UpayCsysTmallTxnLogReq">

    <sequence>

     <element name="bussChl" nillable="true" type="xsd:string"/>

     <element name="bussType" nillable="true" type="xsd:string"/>

     <element name="crmActivityCode" nillable="true" type="xsd:string"/>

     <element name="crmBipCode" nillable="true" type="xsd:string"/>

     <element name="crmCnlType" nillable="true" type="xsd:string"/>

     <element name="crmOprDt" nillable="true" type="xsd:string"/>

     <element name="crmOprId" nillable="true" type="xsd:string"/>

     <element name="crmOprTm" nillable="true" type="xsd:string"/>

     <element name="crmOrgId" nillable="true" type="xsd:string"/>

     <element name="crmRouteInfo" nillable="true" type="xsd:string"/>

     <element name="crmRouteType" nillable="true" type="xsd:string"/>

     <element name="crmRouteVal" nillable="true" type="xsd:string"/>

     <element name="crmSessionId" nillable="true" type="xsd:string"/>

     <element name="crmStartTm" nillable="true" type="xsd:string"/>

     <element name="crmTransDt" nillable="true" type="xsd:string"/>

     <element name="crmTransId" nillable="true" type="xsd:string"/>

     <element name="crmTransTm" nillable="true" type="xsd:string"/>

     <element name="crmTranshDt" nillable="true" type="xsd:string"/>

     <element name="crmTranshId" nillable="true" type="xsd:string"/>

     <element name="crmTranshTm" nillable="true" type="xsd:string"/>

     <element name="intTransCode" nillable="true" type="xsd:string"/>

     <element name="intTxnDate" nillable="true" type="xsd:string"/>

     <element name="intTxnSeq" nillable="true" type="xsd:string"/>

     <element name="intTxnTime" nillable="true" type="xsd:string"/>

     <element name="payMode" nillable="true" type="xsd:string"/>

     <element name="seqId" nillable="true" type="xsd:long"/>

     <element name="settleDate" nillable="true" type="xsd:string"/>

     <element name="tmallActivityCode" nillable="true" type="xsd:string"/>

     <element name="tmallCnlType" nillable="true" type="xsd:string"/>

     <element name="tmallOrgId" nillable="true" type="xsd:string"/>

     <element name="tmallRouteInfo" nillable="true" type="xsd:string"/>

     <element name="tmallTransDt" nillable="true" type="xsd:string"/>

     <element name="tmallTransId" nillable="true" type="xsd:string"/>

     <element name="tmallTransTm" nillable="true" type="xsd:string"/>

     <element name="tmallTranshDt" nillable="true" type="xsd:string"/>

     <element name="tmallTranshId" nillable="true" type="xsd:string"/>

     <element name="tmallTranshTm" nillable="true" type="xsd:string"/>

    </sequence>

   </complexType>

   <element name="getUpayCsysTmallLogResponse">

    <complexType>

     <sequence>

      <element name="getUpayCsysTmallLogReturn" type="impl:UpayCsysTmallTxnLogResp"/>

     </sequence>

    </complexType>

   </element>

   <complexType name="UpayCsysTmallTxnLogResp">

    <sequence>

     <element name="bussChl" nillable="true" type="xsd:string"/>

     <element name="bussType" nillable="true" type="xsd:string"/>

     <element name="intTransCode" nillable="true" type="xsd:string"/>

     <element name="intTxnDate" nillable="true" type="xsd:string"/>

     <element name="intTxnSeq" nillable="true" type="xsd:string"/>

     <element name="intTxnTime" nillable="true" type="xsd:string"/>

     <element name="payMode" nillable="true" type="xsd:string"/>

     <element name="seqId" nillable="true" type="xsd:long"/>

     <element name="settleDate" nillable="true" type="xsd:string"/>

     <element name="tmallActivityCode" nillable="true" type="xsd:string"/>

     <element name="tmallOrgId" nillable="true" type="xsd:string"/>

     <element name="tmallRouteInfo" nillable="true" type="xsd:string"/>

     <element name="tmallTransDt" nillable="true" type="xsd:string"/>

     <element name="tmallTransId" nillable="true" type="xsd:string"/>

     <element name="tmallTransTm" nillable="true" type="xsd:string"/>

    </sequence>

   </complexType>

  </schema>

 </wsdl:types>

 

   <wsdl:message name="getUpayCsysTmallLogResponse">

      <wsdl:part element="impl:getUpayCsysTmallLogResponse" name="parameters">

      </wsdl:part>

   </wsdl:message>

 

   <wsdl:message name="getUpayCsysTmallLogRequest">

      <wsdl:part element="impl:getUpayCsysTmallLog" name="parameters">

      </wsdl:part>

   </wsdl:message>

 

   <wsdl:portType name="UpayCsysTmallTxnLog">

      <wsdl:operation name="getUpayCsysTmallLog">

         <wsdl:input message="impl:getUpayCsysTmallLogRequest" name="getUpayCsysTmallLogRequest">

       </wsdl:input>

         <wsdl:output message="impl:getUpayCsysTmallLogResponse" name="getUpayCsysTmallLogResponse">

       </wsdl:output>

      </wsdl:operation>

   </wsdl:portType>

 

   <wsdl:binding name="UpayCsysTmallTxnLogSoapBinding" type="impl:UpayCsysTmallTxnLog">

      <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>

      <wsdl:operation name="getUpayCsysTmallLog">

         <wsdlsoap:operation soapAction=""/>

         <wsdl:input name="getUpayCsysTmallLogRequest">

            <wsdlsoap:body use="literal"/>

         </wsdl:input>

         <wsdl:output name="getUpayCsysTmallLogResponse">

            <wsdlsoap:body use="literal"/>

         </wsdl:output>

      </wsdl:operation>

   </wsdl:binding>

 

   <wsdl:service name="UpayCsysTmallTxnLogService">

      <wsdl:port binding="impl:UpayCsysTmallTxnLogSoapBinding" name="UpayCsysTmallTxnLog">

         <wsdlsoap:address location="http://localhost:8080/test-axis1/services/UpayCsysTmallTxnLog"/>

      </wsdl:port>

   </wsdl:service>

</wsdl:definitions>

 

2.10 浏览器访问测试web service服务端发布情况

打开浏览器,访问http://localhost:8080/test-axis1/services/UpayCsysTmallTxnLog(注localhost改成web service服务端发布的IP地址)



 

说明web service发布成功。

 

还可以访问http://localhost:8080/test-axis1/services/UpayCsysTmallTxnLog?wsdl,查看webservice服务描述文件



 

 通过wsdl文件,逆向开发webservice服务端

一、创建web项目

webservice是通过http/https协议访问,所以要创建web项目,这里按maven格式来创建web工程(见maven web工程步骤请看maven部分)。



 

二、根据wsdl文件,创建webservice客户端

2.1 选中工程test-axis1-client,右键 New->Other->Web Services->Web Service.



 

在Web service type下拉框选择:Top down java bean Web Service (自顶向下Web服务java bean,这个和上一篇的《eclipse开发webservice服务端是相反的》)。

在Service definition输入框输入:http://192.168.1.101:8080/test-axis1/services/UpayCsysTmallTxnLog?wsdl (服务端提供的wsdl访问地址,确保浏览器能访问这个地址)

 

2.2 点击【Next】按钮

 

 

2.3 按默认配置,继续点击【Next】



 

 

2.4 按默认配置,继续点击【Next】


 

2.5 按默认配置,继续点击【Finish】



 

 

左边红色圈子中的文件都是自动生成的,是按照wsdl文件描述生成的。你会发现代码里有很多错误,那是没有引用响应的jar包,可以在pon.xml文件里加上必要的包,如下:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>com.plg.webservice.axis</groupId>

<artifactId>test-axis1-client</artifactId>

<packaging>war</packaging>

<version>0.0.1-SNAPSHOT</version>

<name>test-axis1-client Maven Webapp</name>

<url>http://maven.apache.org</url>

<dependencies>

<dependency>

<groupId>junit</groupId>

<artifactId>junit</artifactId>

<version>3.8.1</version>

<scope>test</scope>

</dependency>

 

<dependency>

<groupId>axis</groupId>

<artifactId>axis</artifactId>

<version>1.4</version>

</dependency>

 

<dependency>

<groupId>commons-discovery</groupId>

<artifactId>commons-discovery</artifactId>

<version>0.2</version>

</dependency>

 

<dependency>

<groupId>org.apache.axis</groupId>

<artifactId>axis-jaxrpc</artifactId>

<version>1.4</version>

</dependency>

 

<dependency>

<groupId>org.apache.axis</groupId>

<artifactId>axis-saaj</artifactId>

<version>1.4</version>

</dependency>

 

<dependency>

<groupId>wsdl4j</groupId>

<artifactId>wsdl4j</artifactId>

<version>1.5.1</version>

</dependency>

 

</dependencies>

<build>

<finalName>test-axis1-client</finalName>

 

</build>

 

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

eclipse开发webservice服务 的相关文章

  • Java 7 默认语言环境

    我刚刚安装了 jre7 我很惊讶地发现我的默认区域设置现在是 en US 对于jre6 它是de CH 与jre7有什么不同 默认区域设置不再是操作系统之一吗 顺便说一句 我使用的是Windows7 谢谢你的回答 编辑 我已经看到了语言环境
  • 如何使用 JAVA 代码以编程方式捕获线程转储?

    我想通过 java 代码生成线程转储 我尝试使用 ThreadMXBean 为此 但我没有以正确的格式获得线程转储 因为我们正在使用jstack命令 请任何人提供一些帮助 他们是否有其他方式获取线程转储 使用任何其他 API 我想要的线程转
  • 删除优先级队列的尾部元素

    如何删除优先级队列的尾部元素 我正在尝试使用优先级队列实现波束搜索 一旦优先级队列已满 我想删除最后一个元素 优先级最低的元素 Thanks 没有简单的方法 将元素从原始元素复制到新元素 最后一个除外 PriorityQueue remov
  • 为什么 MOVE CURSOR 在 OS X Mountain Lion 上不显示?

    我正在做一个项目 想看看 Swing 提供的每个光标是什么样子的 public class Test public static void main String args JFrame frame new JFrame frame set
  • Spring数据中的本机查询连接

    我有课 Entity public class User Id Long id String name ManyToMany List
  • 如何检测图像是否像素化

    之前有人在 SO 上提出过这样的问题 在Python中检测像素化图像 https stackoverflow com questions 12942365 detecting a pixelated image in python还有关于q
  • 在 MongoDB 和 Apache Solr 之间同步数据的简单方法

    我最近开始使用 MongoDB 和 Apache Solr 我使用 MongoDB 作为数据存储 并且希望 Apache Solr 为我的数据创建索引 以实现应用程序中的搜索功能 经过一些研究 我发现 基本上有两种方法可以在 MongoDB
  • 添加到列表时有没有办法避免循环?

    我想知道这样的代码 List
  • 虽然我的类已加载,但 Class.forName 抛出 ClassNotFoundException

    代码如下 它的作用是加载我放在主目录中的 jar 文件中的所有类 import java io File import java util jar JarFile import java util jar JarEntry import j
  • 当 minifyEnabled 为 true 时 Android 应用程序崩溃

    我正在使用多模块应用程序 并且该应用程序崩溃时minifyEnabled true in the installed模块的build gradle 以下是从游戏控制台检索到的反混淆堆栈跟踪 FATAL EXCEPTION Controlle
  • 我们如何测试包私有类?

    我正在看书Effective Java in Item 13 Minimize the accessibility of classes and members 它提到 为了方便测试 您可能想让类 接口或成员更易于访问 这在某种程度上是好的
  • 寻找局部最小值

    下面的代码正确地找到了数组的局部最大值 但未能找到局部最小值 我已经进行了网络搜索 以找到找到最小值的最佳方法 并且根据这些搜索 我认为我正在使用下面的正确方法 但是 在几天的时间里多次检查每一行之后 下面的代码中有一些我仍然没有看到的错误
  • JAVA中遍历JSON数据

    我是 JSON 新手 我使用 HTTPUrlConnections 并在 JAVA 程序中获得一些响应 响应数据将类似于 data id 1 userId 1 name ABC modified 2014 12 04 created 201
  • Play.application() 的替代方案是什么

    我是 Play 框架的新手 我想读取conf文件夹中的一个文件 所以我用了Play application classloader getResources Data json nextElement getFile 但我知道 play P
  • Karaf / Maven - 无法解决:缺少需求 osgi.wiring.package

    我无法在 Karaf 版本 3 0 1 中启动捆绑包 该包是使用 Maven 构建的并导入gson http mvnrepository com artifact com google code gson gson 2 3 1 我按照要求将
  • 无需登录即可直接从 Alfresco 访问文件/内容

    我的场景是这样的 我有一个使用 ALFRESCO CMS 来显示文件或图像的 Web 应用程序 我正在做的是在 Java servlet 中使用用户名和密码登录 alfresco 并且我可以获得该登录的票证 但我无法使用该票证直接从浏览器访
  • 禁用 Android 菜单组

    我尝试使用以下代码禁用菜单组 但它不起作用 菜单项仍然启用 你能告诉我出了什么问题吗 资源 菜单 menu xml menu menu
  • 源值 1.5 的错误已过时,将在未来版本中删除

    我使用 scala maven plugin 来编译包含 scala 和 java 代码的项目 我已经将源和目标设置为1 7 但不知道为什么maven仍然使用1 5 这是我在 pom xml 中的插件
  • 使用 Java https 上传到 Imgur v3 错误

    我目前正在尝试使用他们当前的 API v3 上传到 imgur 但是我不断收到错误 错误 javax net ssl SSLException 证书中的主机名不匹配 api imgur com imgur com OR imgur com
  • 检查应用程序是否在 Android Market 上可用

    给定 Android 应用程序 ID 包名称 如何以编程方式检查该应用程序是否在 Android Market 上可用 例如 com rovio angrybirds 可用 而 com random app ibuilt 不可用 我计划从

随机推荐