当我们在WEBSERVICES中的方法中使用复杂的BEAN对象时,使用不同的工具,利用WSDL文件产生的类,调用方法不同,产生的类也不同,如用IBM本身的工具和利用AXIS中的WSDL2JAVA工具就明显不同了;所以我们在编码的时候,CLIENT端的调用方法也不同;如利用AXIS中的WSDL2JAVA工具产生的复杂BEAN的调用方法,需要将返回类型进行BeanSerializer和BeanDeserializer定义;代码如下:
public static void main(String[] args)
{
String endpoint = "http://localhost:7777/QuoteEngineIDTH/services/QuoteService";
Service service = new Service();
Call call = null;
try
{
call = (Call) service.createCall();
call.setTargetEndpointAddress(endpoint);
call.setMaintainSession(true);
call.setUseSOAPAction(true);
call.setSOAPActionURI( "http://service.quote.ecommerce.cigna.intl.com");
call.setOperationName("queryProduct");
QName paramerType = new QName("QueryProductParam");
QName returnParamerType = new QName("QueryProductResult");
call.addParameter(
"parameter1",
paramerType,
QueryProductParam.class,
javax.xml.rpc.ParameterMode.IN);
call.setReturnType(returnParamerType);
call.registerTypeMapping(
QueryProductResult.class,
returnParamerType,
new BeanSerializerFactory(
QueryProductResult.class,
returnParamerType),
new BeanDeserializerFactory(
QueryProductResult.class,
returnParamerType));
QueryProductParam queryProductParam = new QueryProductParam();
queryProductParam.setCampaigncode("BOB_CAMPAIGN");
queryProductParam.setCountry("ID");
queryProductParam.setLanguage("en");
queryProductParam.setOffercode("BOB_OFFER");
queryProductParam.setAgent("");
QueryProductResult queryProductResult =
(QueryProductResult) call.invoke(
new Object[] { queryProductParam });
System.out.println(queryProductResult.getResultCode());
}
catch (Exception e)
{
e.printStackTrace();
}
这里就将类QueryProductResult进行了BeanSerializer和BeanDeserializer,因在远程方法访问中,我们需要将对象序列化才能够传送;利用IBM WEBSPHERE中的工具产生的类来访问远程方法都被封装好了,只需要调用其中的类就可以使用,IBM已经将上面的大部分代码定义到工具产生的类中!
public static void main(String[] args)
{
String endpoint = "http://localhost:7777/QuoteEngineIDTH/services/QuoteService";
Service service = new Service();
Call call = null;
try
{
call = (Call) service.createCall();
call.setTargetEndpointAddress(endpoint);
call.setMaintainSession(true);
call.setUseSOAPAction(true);
call.setSOAPActionURI( "http://service.quote.ecommerce.cigna.intl.com");
call.setOperationName("queryProduct");
QName paramerType = new QName("QueryProductParam");
QName returnParamerType = new QName("QueryProductResult");
call.addParameter(
"parameter1",
paramerType,
QueryProductParam.class,
javax.xml.rpc.ParameterMode.IN);
call.setReturnType(returnParamerType);
call.registerTypeMapping(
QueryProductResult.class,
returnParamerType,
new BeanSerializerFactory(
QueryProductResult.class,
returnParamerType),
new BeanDeserializerFactory(
QueryProductResult.class,
returnParamerType));
QueryProductParam queryProductParam = new QueryProductParam();
queryProductParam.setCampaigncode("BOB_CAMPAIGN");
queryProductParam.setCountry("ID");
queryProductParam.setLanguage("en");
queryProductParam.setOffercode("BOB_OFFER");
queryProductParam.setAgent("");
QueryProductResult queryProductResult =
(QueryProductResult) call.invoke(
new Object[] { queryProductParam });
System.out.println(queryProductResult.getResultCode());
}
catch (Exception e)
{
e.printStackTrace();
}
这里就将类QueryProductResult进行了BeanSerializer和BeanDeserializer,因在远程方法访问中,我们需要将对象序列化才能够传送;利用IBM WEBSPHERE中的工具产生的类来访问远程方法都被封装好了,只需要调用其中的类就可以使用,IBM已经将上面的大部分代码定义到工具产生的类中!