天天看點

Teamcenter中SOA調用user service

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