WebServices:别人通过项目的网络地址,调用我们的方法
本文基于IDEA搭建简单的WebServices环境
在IDEA创建项目:java --> java EE (WebServices) --> Version:ApacheAxis-->finish
创建lib文件夹并引入jar包:file-->Project Structure-->Artifacts-->war exploded-->WEB-INF/lib/JAX-WS-Apache Axis
public class HelloWorld {
public String sayTitle(String from) {
String result = "title is" + from;
System.out.println(result);
return result;
}
}
Recomplie....
WebServices-->generate Wsdl from java code-->WEB Servere URL:host:8080//services/service/HelloWorld
<service name="HelloWorldService" provider="java:RPC" style="document" use="literal">
<parameter name="className" value="service.HelloWorld"/>
<parameter name="allowedMethods" value="*"/>
<parameter name="scope" value="Application"/>
<namespace>http://service</namespace>
</service>
http://localhost:8080/services
WebServices-->generate java code from Wsdl-->WEB Servere wsdlURL:http://localhost:8080/services/HelloWorldService?wsdl
创建 test/Test.java
import client.HelloWorldServiceSoapBindingStub;
import org.apache.axis.client.Service;
import java.net.URL;
public class Test {
public static void main(String[] args) {
try {
URL url = new URL("http://localhost:8080/services/HelloWorldService");
HelloWorldServiceSoapBindingStub stub = new HelloWorldServiceSoapBindingStub(url,new Service());
String resp=stub.sayTitle(" test");
System.out.println(resp);
} catch (Exception e) {
e.printStackTrace();
}
}
}