点击【Finish】完成;
完成后,在 WebContent/WEB-INF 下有生成的发布文件
并且:WebContent/下 建立wsdl文件夹并创建 wsdl文件:
获取客户端的IP:
import javax.servlet.http.HttpServletRequest;
import org.apache.axis.MessageContext;
import org.apache.axis.transport.http.HTTPConstants;
private
String getClientIP(){
MessageContext mc = null;
HttpServletRequest request = null;
try {
mc = MessageContext.getCurrentContext(); if (mc == null) throw new Exception("无法获取到MessageContext"); request = (HttpServletRequest) mc .getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST); ip = request.getRemoteAddr();
e.printStackTrace(); }
} return ip; } catch (Exception e) { 用Java调用WebService实例
import java.io.IOException;
import java.net.MalformedURLException;
import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceException;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class PJGLServiceTest {
public void callHello() { try { String endpoint = private static final Log log = public static void main(String[] args) { } PJGLServiceTest tester = new PJGLServiceTest(); //tester.callHello(); tester.callUser(); LogFactory.getLog(PJGLServiceTest.class);
"http://192.168.14.190:8888/BCMS/services/PDAService?wsdl";
String namespace = "http://webservice.sinosoft.com/";
Service service = new Service(); Call call = (Call) service.createCall();
} } call.setOperationName(new QName(namespace,"helloWord")); call.setReturnType(org.apache.axis.Constants.XSD_STRING); try { //远程调用发布的方法 String ret = (String) call.invoke(new Object[] {}); } e.printStackTrace(); e.printStackTrace(); System.out.println("The return value is:" + ret); return; e.printStackTrace(); } catch (IOException e) { } catch (MalformedURLException e) { } catch (ServiceException e) { log.error("call helloWord service error!"); public void callUser() { try { String endpoint =
"http://192.168.14.190:8888/BCMS/services/PDAService?wsdl";
String namespace = "http://webservice.sinosoft.com/"; Service service = new Service(); Call call = (Call) service.createCall();
call.setTimeout(30000); //设置响应超时时间
call.setTargetEndpointAddress(new java.net.URL(endpoint));
//设置接口路径
call.setOperationStyle(org.apache.axis.constants.Style.DEFAULT); //不懂这句什么作用
call.setOperationUse(org.apache.axis.constants.Use.LITERAL);
//不懂这句什么作用
QName qname = new QName(namespace, "loginCheck"); //指定要调用的方法
call.setOperationName(qname);
call.addParameter(new QName(namespace, "userName"), org.apache.axis.encoding.XMLType.XSD_STRING, //
javax.xml.rpc.ParameterMode.IN); org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN); call.addParameter(new QName(namespace, "passWord"),
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING); //设置返回值类型
Object[] obj = {"admin","123"}; //参数
String ret = (String) call.invoke(obj); //调用 并返回结果 System.out.println("Get result :" + ret);
} } } catch (Exception e) { } e.printStackTrace();