import com.teamcenter.clientx.AppXSession; import com.teamcenter.services.internal.strong.core.ICTService; import com.teamcenter.services.internal.strong.core._2011_06.ICT.Arg; import com.teamcenter.services.internal.strong.core._2011_06.ICT.Array; import com.teamcenter.services.internal.strong.core._2011_06.ICT.Entry; import com.teamcenter.services.internal.strong.core._2011_06.ICT.InvokeICTMethodResponse; import com.teamcenter.services.internal.strong.core._2011_06.ICT.Structure; public class CallUserService { public static String call(String serviceID,String inputJson) throws Exception { ICTService ictService = ICTService.getService(AppXSession.getConnection()); Arg[] args = new Arg[2]; args[0] = new Arg(); args[0].val = serviceID; // 第一个参数为UserService的名字 args[1] = new Arg(); args[1].structure = new Structure[1]; args[1].structure[0] = new Structure(); args[1].structure[0].args = new Arg[2]; args[1].structure[0].args[0] = new Arg(); args[1].structure[0].args[0].val = Boolean.toString(true); // 默认这么写 // 名称、类型等参数的传递 args[1].structure[0].args[1] = new Arg(); args[1].structure[0].args[1].array = new Array[1]; args[1].structure[0].args[1].array[0] = new Array(); args[1].structure[0].args[1].array[0].entries = new Entry[1]; args[1].structure[0].args[1].array[0].entries[0] = new Entry(); args[1].structure[0].args[1].array[0].entries[0].val = inputJson; InvokeICTMethodResponse invokeICTMethodResponse = ictService.invokeICTMethod("ICCTUserService", "callMethod", args); if (invokeICTMethodResponse.serviceData.sizeOfPartialErrors() > 0) { printErrorMessage(invokeICTMethodResponse); }else{ String outputJson = invokeICTMethodResponse.output[0].structure[0].args[1].val; return outputJson; } return ""; } public static void printErrorMessage(InvokeICTMethodResponse invokeICTMethodResponse) { int partialErrorNum = invokeICTMethodResponse.serviceData.sizeOfPartialErrors(); for (int i = 0; i < partialErrorNum; i++) { String[] messages = invokeICTMethodResponse.serviceData.getPartialError(i).getMessages(); for (int j = 0; j < messages.length; j++) { System.err.println(messages[j]); } } } } ———————————————— 版权声明:本文为CSDN博主「潇潇_零度」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/qq_41482046/article/details/107504667