try {
URL url = new URL("localhost:8080/testwebservice2/HelloWorld");
Call call = new Call();
SOAPMappingRegistry smr = new SOAPMappingRegistry();
//它用来注册一个以前未知的类型
StringDeserializer sd = new StringDeserializer ();//返序列化器
smr.mapTypes(Constants.NS_URI_SOAP_ENC, new QName ("", "return"), String.class, null, sd);
//第一个为编码风格,OName中的第一个为,第二个为"return"。
call.setSOAPMappingRegistry(smr);
call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);//编码风格
call.setTargetObjectURI("http://gerun.com/");
call.setMethodName("sayHello");
Vector<Parameter> soapParams = new Vector<Parameter>();
soapParams.add(new Parameter("arg0",String.class,"sssss",Constants.NS_URI_SOAP_ENC));
//第一个arg0为参数名,第二个参数为方法中的参数类型,第三个为方法中传的参数,第四个为编码风格(这选的为soap)
call.setParams(soapParams);//设置参数
System.out.println(call.toString());
Response soapResponse = call.invoke(url,"");
System.out.println(call.toString());
if (soapResponse.generatedFault()) {
Fault fault = soapResponse.getFault();
System.out.println(fault);
} else {
Parameter soapResult = soapResponse.getReturnValue();
Object obj = soapResult.getValue();
System.out.println("=== " + obj.toString());
}
} catch (Exception e) {
e.printStackTrace();
}
用sopa读取webservice
最新推荐文章于 2024-11-04 16:16:59 发布
