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]);
            }
        }
    }


}

 

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值