使用 Axis2 创建 Web 服务的步骤 - 客户端代码 [英] Steps in creating a web service using Axis2 - The client code

查看:26
本文介绍了使用 Axis2 创建 Web 服务的步骤 - 客户端代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个网络服务,我的交易工具是:

**

<块引用>

Axis2、Eclipse、Tomcat、Ant

**

我需要从代码创建一个 Web 服务,即编写一个基本的 java 类,该类将具有要在 WSDL 中声明的方法.然后使用 java2WSDL.sh 创建我的 WSDL.

那么,这种方法是否正确:

  1. 使用实际业务逻辑编写我的 Java 类

<块引用>

package packageNamel;公开课你好{公共无效世界(字符串名称){SOP("你好" + 姓名);}}

  1. 现在,当我将这个 Hello.java 传递给 java2WSDL.sh 时,这会给我 WSDL.
  2. 最后,我将编写 services.xml 文件,并使用以下目录结构创建 Hello.aar:

    你好.aar

    • 包名
      • Hello.class
    • 元信息
      • services.xml
      • MANIFEST.MF
      • 你好.WSDL

现在,我假设,当我将 aar 放入 tomcat1/webapps/axis2/WEB-INF/services 时,我的服务将被部署

但是,我的问题来了,我如何访问方法World(String name)???!!,即我对客户端代码一无所知!

请教我制作一个非常基本的网络服务并调用该方法.上述 3 个步骤可能是错误的.这是一个社区维基,可以随意编辑.

谢谢

解决方案

我假设您只对 Web 服务客户端感兴趣?

选项 1

调用 web 服务正在使用 Axis2 REST 支持,对于例子:

http://localhost:8080/axis2/services/MyService/myOperation?param1=one&param2=two

选项 2

使用 SOAPUI.它可以通过读取服务的 WSDL 为您生成 SOAP 消息.我客户的测试人员一直在广泛使用它,但对 Web 服务技术只有非常广泛的了解.令人印象深刻的工具.

选项 3

Groovy 客户端(其他基于 JVM 的语言的方法相同)

使用 wsdl2java 工具为 Shakespeare Web 服务创建客户端存根类:

generate.sh:

$AXIS2_HOME/bin/wsdl2java.sh -d adb -s -o build -uri http://www.xmlme.com/WSShakespeare.asmx?WSDLant -file build/build.xml

GetSpeech.groovy:

//依赖//============导入 com.xmlme.webservices.ShakespeareStub@葡萄([@Grab(group='org.apache.axis2', module='axis2-kernel', version='1.5.1'),@Grab(group='org.apache.axis2', module='axis2-adb', version='1.5.1'),@Grab(group='org.apache.axis2', module='axis2-transport-local', version='1.5.1'),@Grab(group='org.apache.axis2', module='axis2-transport-http', version='1.5.1'),@Grab(group='xerces', module='xercesImpl', version='2.6.2'),@GrabConfig(systemClassLoader=true)])//主程序//============def stub = new ShakespeareStub()//请求有效载荷def request = new ShakespeareStub.GetSpeech()request.setRequest("朋友,罗马人,乡下人")//发送请求响应 = stub.getSpeech(请求)println response.getGetSpeechResult()

使用 -cp 参数将生成的代码添加到脚本的类路径中

groovy -cp build/build/classes GetSpeech

I am trying to create a web service, my tools of trade are:

**

Axis2, Eclipse, Tomcat, Ant

**

I need to create a web service from Code, i.e. Write a basic java class which will have the methods to be declared in the WSDL. Then use java2WSDL.sh to create my WSDL.

So, is this approach correct:

  1. Write my Java class with actual business logic

package packageNamel;

public class Hello{
public void World(String name)
          {
            SOP("Hello" + name);
          }
}

  1. Now, when I pass this Hello.java to java2WSDL.sh, this will give me the WSDL.
  2. Finally, I will write the services.xml file, and create the Hello.aar with following dir structure:

    Hello.aar

    • packageName
      • Hello.class
    • META-INF
      • services.xml
      • MANIFEST.MF
      • Hello.WSDL

Now, I assume, my service will be deployed when I put the aar in tomcat1/webapps/axis2/WEB-INF/services

But, here comes my problem, HOW DO I ACCESS THE METHOD World(String name)???!!, i.e. I am clueless about the client code!

Please enlighten me on making a very basic web service and calling the method. The above described 3 steps might be wrong. It's a community wiki, feel free to edit.

Thanks

解决方案

I'm assuming you're only interested in web service clients?

Option 1

Invoke the web service is using Axis2 REST support, for example:

http://localhost:8080/axis2/services/MyService/myOperation?param1=one&param2=two

Option 2

Use SOAPUI. It can generate SOAP messages for you, by reading your service's WSDL. My client's testers have been using it extensively with only a very broad understanding of web service technologies. An impressive tool.

Option 3

Groovy client (Same approach for other JVM based languages)

Use the wsdl2java tool to create a client stub class for the Shakespeare web service:

generate.sh:

$AXIS2_HOME/bin/wsdl2java.sh -d adb -s -o build -uri http://www.xmlme.com/WSShakespeare.asmx?WSDL
ant -file build/build.xml 

GetSpeech.groovy:

// Dependencies
// ============
import com.xmlme.webservices.ShakespeareStub

@Grapes([
    @Grab(group='org.apache.axis2', module='axis2-kernel', version='1.5.1'),
    @Grab(group='org.apache.axis2', module='axis2-adb', version='1.5.1'),
    @Grab(group='org.apache.axis2', module='axis2-transport-local', version='1.5.1'),
    @Grab(group='org.apache.axis2', module='axis2-transport-http', version='1.5.1'),
    @Grab(group='xerces', module='xercesImpl', version='2.6.2'),
    @GrabConfig(systemClassLoader=true)
])

// Main program
// ============
def stub = new ShakespeareStub()

// Request payload
def request = new ShakespeareStub.GetSpeech()
request.setRequest("Friends, romans, countrymen")

// Send request
response = stub.getSpeech(request)

println response.getGetSpeechResult()

Use the -cp parameter to add the generated code the the script's classpath

groovy -cp build/build/classes GetSpeech

这篇关于使用 Axis2 创建 Web 服务的步骤 - 客户端代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆