简体   繁体   English

wsdl2java和axis2 webservice设置和测试

[英]wsdl2java and axis2 webservice setup and testing

I am very new to the building of web-services, so please forgive my ignorance. 我对网络服务的建设很陌生,所以请原谅我的无知。

I have been given some an .wsdl files with some .xsd files that it imports. 我得到了一些.wsdl文件,其中包含一些导入的.xsd文件。

I am told that a web-service can be created from the .wsdl file by using wsdl2java from the apache axis2 project. 我被告知可以使用来自apache axis2项目的wsdl2java.wsdl文件创建Web服务。

The web-service I am trying to build is expecting to have data pushed to it and I would like to test it that I have the process right for data to be pushed to a web-service that I created. 我正在尝试构建的Web服务期望将数据推送到它,并且我想测试它,我有正确的流程将数据推送到我创建的Web服务。

The basis for my actions have been from here , but not too sure how much of it is applicable. 我的行动的基础来自这里 ,但不太确定它有多少适用。

I am on a MacOSX but also have access to an ubuntu system too. 我在MacOSX上,但也可以访问ubuntu系统。

the steps I have taken so far are: 到目前为止我采取的步骤是:

cd /directory/of/wsdl/file
wsdl2java.sh -uri tmp.wsdl -d adb -s

This creates a build.xml file and src directory 这将创建一个build.xml文件和src目录

I then try and run 然后我试着跑

ant 

or 要么

ant jar.client

After this I am not too sure what to do, in order to get the web-server running so that I could test it...any suggestions would be greatly appreciated. 在此之后,我不太清楚该怎么做,为了让网络服务器运行,以便我可以测试它...任何建议将不胜感激。

Thanks in advance. 提前致谢。

In SOAP web service:- The basic concept in web service is that it has consumer and producer. 在SOAP Web服务中: - Web服务的基本概念是它具有消费者和生产者。 A consumer is one which consumes a web service and a producer is one which produces a web service. 消费者是消费Web服务的消费者,生产者是生成Web服务的消费者。 A producer publish its service so that consumer can consume it. 生产者发布其服务,以便消费者可以使用它。 It basically publishes a wsdl file so that you can create a client code or jar out of it and can directly call it from your code. 它基本上发布了一个wsdl文件,以便您可以创建一个客户端代码或jar,并可以直接从您的代码中调用它。 You can use soap UI to call the web service directly as well. 您也可以使用soap UI直接调用Web服务。 If you are looking for generating producer code from wsdl as well it will not be good enough since it will not provide business logic to you and you need to implement it by yourself. 如果您正在寻找从wsdl生成生产者代码,那么它将不够好,因为它不会为您提供业务逻辑,您需要自己实现它。 This is not a recommended approach. 这不是推荐的方法。 Generally first java implementation is written and based on it a wsdl is created from which client jars are created for the clients to use the web service in their code. 通常首先编写java实现,并基于它创建一个wsdl,从中创建客户端jar,以便客户端在其代码中使用Web服务。 For directly testing the producer soapui is used. 为了直接测试生产者使用soapui。 If you want to create producer it is a straight forward process. 如果你想创建生产者,那么这是一个直接的过程。 Need to create a dynamic project in eclipse-->create a class-->use @WebService(serviceName="xyz") on class and similarly on method level define @WebMethod. 需要在eclipse中创建一个动态项目 - >创建一个类 - >在类上使用@WebService(serviceName =“xyz”),类似地在方法级别定义@WebMethod。 Deploy it as run on server and you are done with your Hello World Web service producer. 将其部署为在服务器上运行,并且您已完成Hello World Web服务生产者。

For creating the client:- 用于创建客户端: -

Lets take an example of a published wsdl on the net as :- 让我们举一个网上发布的wsdl的例子: -

http://www.webservicex.net/geoipservice.asmx?WSDL

First you need to create the client jar or java classes as :- 首先,您需要创建客户端jar或java类: -

wsimport -keep -s C:\wsdl http://www.webservicex.net/geoipservice.asmx?WSDL

Look at the documentation or look at the service name in the wsdl. 查看文档或查看wsdl中的服务名称。 It will be GeoIPService. 它将是GeoIPService。 Now in your class call the webservice method as:- 现在在您的类中将webservice方法称为: -

package com.soap.client;

import net.webservicex.GeoIP;
import net.webservicex.GeoIPService;
import net.webservicex.GeoIPServiceSoap;
public class SoapWebServiceClient {

    public static void main(String[] args) {
        GeoIPService ipService = new GeoIPService();
        GeoIPServiceSoap gp = ipService.getGeoIPServiceSoap();
        GeoIP ip = gp.getGeoIP("117.198.208.1"); //google.com
        System.out.println(ip.getCountryName());
    }

}

Now similarly for local wsdl you can create classes and jars by using axis2 or simply wsimport 现在,对于本地wsdl,您可以使用axis2或简单地使用wsimport创建类和jar

Put your wsdl and schemas in a folder as shown below:- 将您的wsdl和模式放在一个文件夹中,如下所示: -

C:\wsdl>wsimport -keep -s C:\wsdl C:\wsdl
C:\wsdl>wsimport -clientjar client.jar C:\wsdl

It will create a client for you. 它将为您创建一个客户端。 Look at the service name and similarly can test the deployed service from java code as shown above. 查看服务名称,同样可以从java代码测试已部署的服务,如上所示。

For testing using soapui you use need to download it and create a new soap project. 要使用soapui进行测试,您需要下载它并创建一个新的soap项目。 Give any name and browse to your local drive where all the schema and wsdl is present. 提供任何名称并浏览到所有架构和wsdl所在的本地驱动器。 It will create all the requests for your. 它会为您创建所有请求。 You need to fill in the values in the request parameters ("?") and run the service. 您需要填写请求参数(“?”)中的值并运行该服务。 If everything went well it will display a result. 如果一切顺利,它将显示结果。

Note:- 注意:-

wsimport is a command line tool for the JAX-WS reference implementation. wsimport是JAX-WS参考实现的命令行工具。 The JAX-WS RI uses JAXB for data-binding. JAX-WS RI使用JAXB进行数据绑定。

Axis2 merely implements the JAX-WS API to some extent, so the Java artifacts generated can be quite different compared to those generated by the JAX-WS RI. Axis2仅在某种程度上实现了JAX-WS API,因此与JAX-WS RI生成的Java工件相比,生成的Java工件可能完全不同。 Also Axis2 doesn't use JAXB but instead offers the choice of ADB (default), Apache XmlBeans, or JiBX for data-binding. Axis2也不使用JAXB,而是提供ADB(默认),Apache XmlBeans或JiBX的数据绑定选择。 The most popularly used are either xmlbeans or JAXB. 最常用的是xmlbeans或JAXB。

您从发布URL查找wsdl文件并对Web服务进行反向工程以生成类型,因此请使用wsimport

wsimport -d . -p servicesource -keep tmp.wsdl 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM