Axis Webservice Demo

Interface:

 

 

public interface UserService {

 

public String getUserName(String name);

 

public String getPassWord(String password);

}


Impl:

public class UserServiceImpl implements UserService {
@Override
public String getPassWord(String password) {
return password;
}

@Override
public String getUserName(String name) {
return name;
}
}

WSDD:(UserService.wsdd)和web.xml放在同一目录
<deployment xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<service name="UserService" provider="java:RPC">
<parameter name="className"
value="com.bsf.gwtservice.UserServiceImpl" />
<parameter name="allowedMethods" value="*" />
</service>
</deployment>
在web.xml中配置 axis Servlet:
<servlet>
<servlet-name>AxisServlet</servlet-name>
<servlet-class>
org.apache.axis.transport.http.AxisServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
进入DOS路径切换到你Tomcat....WEB-INF执行:(axis相关包必须配置到环境变量classpath中)
java org.apache.axis.client.AdminClient -lhttp://localhost:9100/GwtService/services/AdminService UserService.wsdd

成功会显示:<Admin>Done processing</Admin> 
在web-inf 下生成server-config.wsdd

客户端调用:(我用的是eclipse3.7)
我想生成客户端简单的方法应该是:访问地址: http://localhost:9100/GwtService/services/UserService?wsdl
文件另存为扩展名为.wsdl拷贝到工程src下面 右键->web services->Generate Client->后面就自己设置就OK了


测试类:
public class Test {
public static void main(String[] args) throws Exception {
UserServiceImplServiceLocator locator = new UserServiceImplServiceLocator();
UserServiceSoapBindingStub service = (UserServiceSoapBindingStub) locator
.getPort(UserServiceSoapBindingStub.class);
System.out.println(service.getPassWord("password"));
System.out.println(service.getUserName("userName"));

}
}


你可能感兴趣的:(webservice,axis)