本帖最后由 karrman 于 2017-1-11 16:03 编辑
Q:如何通过在java中调用平台webservice接口得到数据?
A:请参考以下脚本:
package webService;
public class SyncTest {
public static void main(String[] args) {
//部门同步
String url="http://localhost:8080/obpm/services/DepartmentService";
String pk ="11e6-4314-767bf282-a2bd-77e1f101bc4d";
String xmlStr = "<cn.myapps.webservice.model.SimpleDepartment>/n"
+ " <domainName>万佳信息工程公司</domainName>/n"
+ " <id></id>/n"
+ " <level></level>/n"
+ " <name>部门111111111</name>/n"
+ " <superiorName>Xml格式部门</superiorName>/n"
+ " </cn.myapps.webservice.model.SimpleDepartment>/n";
XfireClient xfireClient=new XfireClient();
xfireClient.createDepartment(url, xmlStr);
//xfireClient.getDepartment(url, pk);
//xfireClient.updateDepartment(url, xmlStr);
//xfireClient.deleteDepartment(url, pk);
}
}
package webService;
import java.net.MalformedURLException;
import org.codehaus.xfire.client.XFireProxyFactory;
import org.codehaus.xfire.service.Service;
import org.codehaus.xfire.service.binding.ObjectServiceFactory;
import test.IAnyName;
/**
* 这是xfire客户端
* 创建
* @author Administrator
*
*/
public class XfireClient {
public XfireClient(){
}
public String createDepartment(String url,String xmlStr){
try {
Service service = new ObjectServiceFactory().create(TLInterface.class) ;
XFireProxyFactory factory = new XFireProxyFactory() ;
TLInterface tlInterface = (TLInterface) factory.create(service,url) ;
String result=tlInterface.createDepartmentFromXML(xmlStr);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
package webService;
public interface TLInterface {
public int createDepartmentFromXML(String xmlStr);
public int updateDepartmentFromXML(String xmlStr);
public String findDepartmentFormat2XML(String pk);
public int deleteDepartment(String pk);
} |