webservice有两个应用 A应用和B应用A应用提供webservice接口。。 B应用调用A应用的接口, 然后插入数据到A应用中(数据是从B中查询得到的),想请问下A应用是怎么接受数据的。
是用的axis2
这是客户端(同上的B应用)
package client;
import javax.xml.namespace.QName;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;
public class StudentRPCClient {
/**
* @param args
* @throws AxisFault
*/
public static void main(String[] args) throws Exception {
RPCServiceClient serviceClient = new RPCServiceClient();
Options options = serviceClient.getOptions();
EndpointReference targetEPR = new EndpointReference("http://localhost:8080/axis2/services/StudentService");
//EndpointReference targetEPR = new EndpointReference("http://localhost:8080/axis2/services/StudentService");
options.setTo(targetEPR);
// QName opAddEntry = new QName("http://ws.apache.org/axis2", "getAllStudent");
// String[] strArray = (String[]) serviceClient.invokeBlocking(opAddEntry, new Object[]{}, new Class[]{String[].class})[0];
//
// for (String s : strArray)
// {
// String[] array = s.split(",");
// for(String ss: array) System.out.print("<" + ss + "> "); System.out.println();
// }
System.out.println();
Class[] classes=new Class[]{String.class};
QName opAddEntry = new QName("http://ws.apache.org/axis2", "insertUser");
System.out.println(serviceClient.invokeBlocking(opAddEntry,new Object[]{},classes)[0]);
}
}
这是服务端(同上A应用)
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.Header;
import org.apache.http.HeaderIterator;
import org.apache.http.HttpRequest;
import org.apache.http.ProtocolVersion;
import org.apache.http.RequestLine;
import org.apache.http.params.HttpParams;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;
import conn.GetAllStu;
import data.Student;
public class StudentService{
// public int end=1;
// public String[] getAllStudent()
// {
// GetAllStu getStu=new GetAllStu();
// List<Student> list=getStu.getAllStudent();
// int num=Integer.valueOf(list.size());
// String[] str=new String[num];
// for(int i=0;i<list.size();i++)
// {
// str[i]=String.valueOf(list.get(i).getId())+","+list.get(i).getName()+","+list.get(i).getAddress();
// }
// return str;
// }
public String insertUser() throws SQLException
{
String userName="";
String password="";
String user="root";
String pass="";
String url="jdbc:mysql://localhost:3306/xindou_db";
String driver="com.mysql.jdbc.Driver";
Connection conn=null;
Statement st=null;
ResultSet rs=null;
List<Student> list=new ArrayList<Student>();
try {
Class.forName(driver);
conn=(Connection) DriverManager.getConnection(url, user, pass);
st = (Statement) conn.createStatement();
String sqlstr="insetr into t_user('"+userName+"','"+password+"')";
rs=st.executeQuery(sqlstr);
}catch(Exception e)
{
e.printStackTrace();
}finally
{
rs.close();
st.close();
conn.close();
}
return "1";
}
}
------解决方案--------------------
你不是都发布好了吗?发布好了就直接获取。你浏览器把地址输入,然后参数录入。就如
这样的http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?op=getSupportCity
------解决方案--------------------
webservice 发布出来
------解决方案--------------------
我无论使用Axis2 MyEclipse Plugin还是Axis2 提供的 WSDL2Java.bat工具来生成客户端,生成之后的客户端都比较混乱,里面代码格式乱七八糟,对于一些复杂对象,生成的实体类里面方法特别乱,我想生成客户端的实体类跟服务端的实体类完全一样,请问有什么办法可以实现?就是没有其他多余的方法。