使用Axis2创建Web服务的步骤 - 客户端代码 [英] Steps in creating a web service using Axis2 - The client code
问题描述
我正在尝试创建一个网络服务,我的交易工具是:
I am trying to create a web service, my tools of trade are:
**
Axis2,Eclipse,Tomcat,Ant
Axis2, Eclipse, Tomcat, Ant
**
我需要从Code创建一个Web服务,即编写一个基本的java类,它将具有在WSDL中声明的方法。然后使用java2WSDL.sh创建我的WSDL。
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:
- 用实际业务逻辑编写我的Java类
package packageNamel;
public class Hello{
public void World(String name)
{
SOP("Hello" + name);
}
}
- 现在,当我将此Hello.java传递给java2WSDL.sh时,这将为我提供WSDL。
-
最后,我将编写services.xml文件,并使用以下dir结构创建Hello.aar:
- Now, when I pass this Hello.java to java2WSDL.sh, this will give me the WSDL.
Finally, I will write the services.xml file, and create the Hello.aar with following dir structure:
Hello.aar
Hello.aar
- packageName
- Hello.class
- services.xml
- MANIFEST.MF
- Hello.WSDL
现在,我假设,当我把aar放在tomcat1 / webapps / axis2 / WEB-INF / services
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!请告诉我制作一个非常基本的Web服务并调用该方法。上述3个步骤可能是错误的。这是一个社区维基,随时可以编辑。
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.
谢谢
推荐答案
我假设您只对网络服务客户感兴趣?
I'm assuming you're only interested in web service clients?
调用网络服务正在使用Axis2 REST支持,例如:
Invoke the web service is using Axis2 REST support, for example:
http:/ / localhost:8080 / axis2 / services / MyService / myOperation?param1 = one& param2 = 2
使用 SOAPUI 。它可以通过读取服务的WSDL为您生成SOAP消息。我的客户的测试人员一直在广泛使用它,只是对Web服务技术有非常广泛的了解。一个令人印象深刻的工具。
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.
Groovy客户端(其他基于JVM的语言的方法相同)
Groovy client (Same approach for other JVM based languages)
使用 wsdl2java 工具为莎士比亚网络服务创建客户端存根类:
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()
使用-cp参数将生成的代码添加到脚本的类路径中
Use the -cp parameter to add the generated code the the script's classpath
groovy -cp build/build/classes GetSpeech
这篇关于使用Axis2创建Web服务的步骤 - 客户端代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!