[英]Steps in creating a web service using Axis2 - The client code
I am trying to create a web service, my tools of trade are: 我正在尝试创建一个Web服务,我的交易工具是:
** **
Axis2, Eclipse, Tomcat, Ant
Axis2,Eclipse,Tomcat,Ant
** **
I need to create a web service from Code, ie Write a basic java class which will have the methods to be declared in the WSDL. 我需要从Code创建一个Web服务,即编写一个基本的java类,它将具有在WSDL中声明的方法。 Then use java2WSDL.sh to create my WSDL.
然后使用java2WSDL.sh创建我的WSDL。
So, is this approach correct: 那么,这种方法是否正确:
package packageNamel; public class Hello{ public void World(String name) { SOP("Hello" + name); } }
Finally, I will write the services.xml file, and create the Hello.aar with following dir structure: 最后,我将编写services.xml文件,并使用以下dir结构创建Hello.aar:
Hello.aar Hello.aar
Now, I assume, my service will be deployed when I put the aar in tomcat1/webapps/axis2/WEB-INF/services 现在,我假设,当我将aar放入tomcat1 / webapps / axis2 / WEB-INF / services时,我的服务将被部署
But, here comes my problem, HOW DO I ACCESS THE METHOD World(String name)
???!!, ie I am clueless about the client code! 但是,这是我的问题,我如何访问方法
World(String name)
??? !!,即我对客户端代码一无所知!
Please enlighten me on making a very basic web service and calling the method. 请赐教我制作一个非常基本的Web服务并调用该方法。 The above described 3 steps might be wrong.
上述3个步骤可能是错误的。 It's a community wiki, feel free to edit.
这是一个社区维基,随时可以编辑。
Thanks 谢谢
I'm assuming you're only interested in web service clients? 我假设你只对网络服务客户感兴趣?
Invoke the web service is using Axis2 REST support , for example: 调用Web服务正在使用Axis2 REST支持 ,例如:
http://localhost:8080/axis2/services/MyService/myOperation?param1=one¶m2=two HTTP://本地主机:8080 /的Axis2 /服务/为MyService / myOperation参数1 =一个&参数2 =两个
Use SOAPUI . 使用SOAPUI 。 It can generate SOAP messages for you, by reading your service's WSDL.
它可以通过读取服务的WSDL为您生成SOAP消息。 My client's testers have been using it extensively with only a very broad understanding of web service technologies.
我的客户的测试人员一直在广泛使用它,只是对Web服务技术的广泛理解。 An impressive tool.
令人印象深刻的工
Groovy client (Same approach for other JVM based languages) Groovy客户端(其他基于JVM的语言的方法相同)
Use the wsdl2java tool to create a client stub class for the Shakespeare web service: 使用wsdl2java工具为莎士比亚Web服务创建客户端存根类:
generate.sh : 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 : 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 使用-cp参数将生成的代码添加到脚本的类路径中
groovy -cp build/build/classes GetSpeech
If you have access to the WSDL,the following code/ JAX-WS client can be used to invoke any SOAP based web service. 如果您有权访问WSDL,则可以使用以下代码/ JAX-WS客户端来调用任何基于SOAP的Web服务。
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
public class WebserviceClient {
public static void main(String[] args) throws Exception {
URL url = new URL
("http://localhost:9999/ws/additionService?wsdl");
QName qname = new QName("http://test/",
"AdditionServiceImplService");//Line 2
Service service = Service.create(url, qname);
AdditionService additionService = service
.getPort(AdditionService.class);
System.out.println(additionService.add(1, 2));
}
}
In Line 2, QName
first argument is the namespace used in WSDL and second argument is simply the service name. 在第2行中,
QName
第一个参数是WSDL中使用的命名空间,第二个参数只是服务名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.