In this tutorial I will teach you the simplest way to create Java SOAP web service using Eclipse IDE.
在本教程中,我将教您使用Eclipse IDE创建Java SOAP Web服务的最简单方法。
I have created this example using Eclipse Kepler. I am sure it will work with any other Eclipse version. But make sure your IDE contains Apache Tomcat and Apache Axis.
我已经使用Eclipse Kepler创建了这个示例。 我确信它将与任何其他Eclipse版本一起使用。 但是请确保您的IDE包含Apache Tomcat和Apache Axis 。
Apache Axis will do the work of creating web service using Java source file and Apache Tomcat server will be used to run and test the web service.
Apache Axis将完成使用Java源文件创建Web服务的工作,而Apache Tomcat服务器将用于运行和测试Web服务。
So without wasting any time lets begin the process.
因此,不要浪费任何时间让我们开始这一过程。
使用Eclipse创建Java SOAP Web服务 (Create Java SOAP Web Service Using Eclipse)
1. First of all open Eclipse and go to File > New > Dynamic Web Project
1.首先打开Eclipse,然后转到File> New> Dynamic Web Project。
2. Give a project name and then click on Finish button to create a dynamic web project.
2.指定一个项目名称,然后单击“ 完成”按钮以创建一个动态Web项目。
3. Now create a Java class inside src folder in com package. You can choose the package and class name according to you.
3.现在,在com包的src文件夹内创建一个Java类。 您可以根据自己的需要选择包和类名称。
4. For demonstration purpose I am creating a function in our class that will take two numbers and return sum of these two numbers. Add following code in your class. You can create more functions according to your requirement.
4.为了演示的目的,我在类中创建一个函数,该函数将接收两个数字并返回这两个数字的和。 在您的班级中添加以下代码。 您可以根据需要创建更多功能。
|
1
2
3
4
5
6
7
|
package com;
public class DemoClass {
public String func(int a,int b){
return String.valueOf(a+b);
}
}
|
|
1
2
3
4
5
6
7
|
package com ;
public class DemoClass {
public String func ( int a , int b ) {
return String . valueOf ( a + b ) ;
}
}
|
5. Right click on Java class and go to Web Services > Create Web Service.
5.右键单击Java类,然后转到Web服务>创建Web服务 。
6. Select all the settings as given in below screenshot. Finally click on Finish button to create the web service.
6.选择以下屏幕截图中给出的所有设置。 最后,单击“ 完成”按钮以创建Web服务。
7. After the web service is created a browser will be opened. Here we have to test our web service is working properly or not.
7.创建Web服务后,将打开浏览器。 在这里,我们必须测试我们的Web服务是否正常工作。
8. Under Methods you can see all the methods that we have in our class. In this case we have only one method func(). Click on it, now enter values of arguments a and b in the text boxes provided. Finally click on Invoke button to invoke the method. You can see the result of the method under Result.
8.在“ 方法”下,您可以看到我们班级中拥有的所有方法。 在这种情况下,我们只有一个方法func() 。 单击它,现在在提供的文本框中输入参数a和b的值。 最后单击“ 调用”按钮以调用该方法。 您可以在Result下查看该方法的结果 。
9. A WSDL file is created in SOAP web service. It contains all the details of the web service. Like name of methods, name of arguments, return type, etc. You can see the WSDL file by going to folder WebContent > wsdl.
9.在SOAP Web服务中创建了WSDL文件。 它包含Web服务的所有详细信息。 像方法名称,参数名称,返回类型等。您可以通过转到WebContent> wsdl文件夹查看WSDL文件。
10. In our case the WSDL file will look like this.
10.在本例中,WSDL文件将如下所示。
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://com" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://com" xmlns:intf="http://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://com" xmlns="http://www.w3.org/2001/XMLSchema">
<element name="func">
<complexType>
<sequence>
<element name="a" type="xsd:int"/>
<element name="b" type="xsd:int"/>
</sequence>
</complexType>
</element>
<element name="funcResponse">
<complexType>
<sequence>
<element name="funcReturn" type="xsd:string"/>
</sequence>
</complexType>
</element>
</schema>
</wsdl:types>
<wsdl:message name="funcRequest">
<wsdl:part element="impl:func" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="funcResponse">
<wsdl:part element="impl:funcResponse" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="DemoClass">
<wsdl:operation name="func">
<wsdl:input message="impl:funcRequest" name="funcRequest">
</wsdl:input>
<wsdl:output message="impl:funcResponse" name="funcResponse">
</wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="DemoClassSoapBinding" type="impl:DemoClass">
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="func">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="funcRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="funcResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="DemoClassService">
<wsdl:port binding="impl:DemoClassSoapBinding" name="DemoClass">
<wsdlsoap:address location="http://localhost:8080/SOAPExample/services/DemoClass"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
|
观看**** (Watch Video Tutorial)
So, this was the simplest way to create Java SOAP web service using eclipse. Comment below if you are facing any problem. I will try my best to help you.
因此,这是使用eclipse创建Java SOAP Web服务的最简单方法。 如果您遇到任何问题,请在下面评论。 我会尽力为您服务。
翻译自: https://www.thecrazyprogrammer.com/2016/02/create-java-soap-web-service-using-eclipse.html