场景:通过网络接口给手机发送信息
方式:axis的方式进行webservice访问
问题:1.在本地独立的tomcat下跑,一点问题没有
2.同样打包的项目放到正式机上,只要一发送信息就出现java.net.ConnectException: Connection refused: connect,造成信息无法发出
3.正式机防火墙关了,并且我发现正式机上面无法ping通给的ws的url,但是通过网页是可以访问到那个url!
3.部分代码如下:
private String login() {
String result = "";
System.out.println("開始調用WebService,開始獲取登入信息!");
log.info("開始調用WebService,開始獲取登入信息!");
try {
// WebService所在的URL
String endpoint = "http://tw.every8d.com/API20/Security.asmx";
log.info("endpoint== "+endpoint);
// 創建Service對象,Service用於創建Call對象
Service service = new Service();
// 創建Call對象,Call對象用於調用服務
Call call = (Call) service.createCall();
// 為Call對象設置WebService的url
call.setTargetEndpointAddress(new java.net.URL(endpoint));
// 為Call對象設置調用的方法名
call.setOperationName(new QName("http://tempuri.org/", "Login"));
// 該方法需要的參數
call.addParameter(new javax.xml.namespace.QName(
"http://tempuri.org/", "custID"),
org.apache.axis.encoding.XMLType.XSD_STRING,
javax.xml.rpc.ParameterMode.IN);
call.addParameter(new javax.xml.namespace.QName(
"http://tempuri.org/", "userID"),
org.apache.axis.encoding.XMLType.XSD_STRING,
javax.xml.rpc.ParameterMode.IN);
call.addParameter(new javax.xml.namespace.QName(
"http://tempuri.org/", "password"),
org.apache.axis.encoding.XMLType.XSD_STRING,
javax.xml.rpc.ParameterMode.IN);
call.addParameter(new javax.xml.namespace.QName(
"http://tempuri.org/", "APIType"),
org.apache.axis.encoding.XMLType.XSD_STRING,
javax.xml.rpc.ParameterMode.IN);
call.addParameter(new javax.xml.namespace.QName(
"http://tempuri.org/", "version"),
org.apache.axis.encoding.XMLType.XSD_STRING,
javax.xml.rpc.ParameterMode.IN);
// 方法返回的值類型
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
call.setUseSOAPAction(true);
call.setSOAPActionURI("http://tempuri.org/Login");
String custID = accountsUtil.getCustID();
log.info("custID=="+custID);
String userID = accountsUtil.getUserID();
log.info("userID=="+userID);
String password = accountsUtil.getPassword();
log.info("password=="+password);
String APIType = "";
String version = "";
// 調用WebService的放到,并獲得返回值
result = (String) call.invoke(new Object[] { custID, userID,
password, APIType, version });//进行登录验证的时候就出错
System.out.println(result);
log.info("before result"+result);
} catch (Exception e) {
log.info(e);
System.out.println(e);
System.out.println("賬戶登入失敗,異常!");
}
System.out.println("調用Web Service正常結束,獲取登入信息結束!");
log.info("end result"+result);
return result;
}
方式:axis的方式进行webservice访问
问题:1.在本地独立的tomcat下跑,一点问题没有
2.同样打包的项目放到正式机上,只要一发送信息就出现java.net.ConnectException: Connection refused: connect,造成信息无法发出
3.正式机防火墙关了,并且我发现正式机上面无法ping通给的ws的url,但是通过网页是可以访问到那个url!
3.部分代码如下:
private String login() {
String result = "";
System.out.println("開始調用WebService,開始獲取登入信息!");
log.info("開始調用WebService,開始獲取登入信息!");
try {
// WebService所在的URL
String endpoint = "http://tw.every8d.com/API20/Security.asmx";
log.info("endpoint== "+endpoint);
// 創建Service對象,Service用於創建Call對象
Service service = new Service();
// 創建Call對象,Call對象用於調用服務
Call call = (Call) service.createCall();
// 為Call對象設置WebService的url
call.setTargetEndpointAddress(new java.net.URL(endpoint));
// 為Call對象設置調用的方法名
call.setOperationName(new QName("http://tempuri.org/", "Login"));
// 該方法需要的參數
call.addParameter(new javax.xml.namespace.QName(
"http://tempuri.org/", "custID"),
org.apache.axis.encoding.XMLType.XSD_STRING,
javax.xml.rpc.ParameterMode.IN);
call.addParameter(new javax.xml.namespace.QName(
"http://tempuri.org/", "userID"),
org.apache.axis.encoding.XMLType.XSD_STRING,
javax.xml.rpc.ParameterMode.IN);
call.addParameter(new javax.xml.namespace.QName(
"http://tempuri.org/", "password"),
org.apache.axis.encoding.XMLType.XSD_STRING,
javax.xml.rpc.ParameterMode.IN);
call.addParameter(new javax.xml.namespace.QName(
"http://tempuri.org/", "APIType"),
org.apache.axis.encoding.XMLType.XSD_STRING,
javax.xml.rpc.ParameterMode.IN);
call.addParameter(new javax.xml.namespace.QName(
"http://tempuri.org/", "version"),
org.apache.axis.encoding.XMLType.XSD_STRING,
javax.xml.rpc.ParameterMode.IN);
// 方法返回的值類型
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
call.setUseSOAPAction(true);
call.setSOAPActionURI("http://tempuri.org/Login");
String custID = accountsUtil.getCustID();
log.info("custID=="+custID);
String userID = accountsUtil.getUserID();
log.info("userID=="+userID);
String password = accountsUtil.getPassword();
log.info("password=="+password);
String APIType = "";
String version = "";
// 調用WebService的放到,并獲得返回值
result = (String) call.invoke(new Object[] { custID, userID,
password, APIType, version });//进行登录验证的时候就出错
System.out.println(result);
log.info("before result"+result);
} catch (Exception e) {
log.info(e);
System.out.println(e);
System.out.println("賬戶登入失敗,異常!");
}
System.out.println("調用Web Service正常結束,獲取登入信息結束!");
log.info("end result"+result);
return result;
}
返回结果又很慢。可以试试socket.ejb之类的。