利用axis1 客户端调用cxf写的webservice接口
客户端:JDK1.5, axis1
服务端:JDK1.7,spring集成cxf发布的webservice
-------------------------------------------------------------以下是JDK1.7的运行结果-------------------------------------------------------------
-------------------------------------------------------------以下是JDK1.5的运行结果-------------------------------------------------------------
最后只能用axis1的客户端调用cxf了,具体代码如下:
package call_webservices; import java.io.FileInputStream; import java.io.FileNotFoundException; import org.apache.axis.client.Call; import org.apache.axis.client.Service; import org.apache.axis.message.SOAPHeaderElement; import org.jdom.Document; import javax.xml.namespace.QName; import com.JdomUtil; public class AxisClienCallCXFWebservice { public static void test1(String Str) throws Exception { Service service = new Service(); Call call = (Call) service.createCall(); String url = "http://localhost:8080/channel-access/soap/ycbsService?wsdl"; call.setTargetEndpointAddress(url); // 设置命名空间和方法名,命名空间需要和@WebService注解的targetNamespace一致 call.setOperationName(new QName("http://cxf.sinosoft.com/", "ycbsService")); // 添加头信息,用于权限校验。QName的参数命名随意 SOAPHeaderElement header = new SOAPHeaderElement(new QName("ABC")); header.setActor(null); header.addChildElement("ABC").addTextNode("testABC"); call.addHeader(header); // 设置参数,这里调用一次addParameter,表示添加一个参数,然后定义接口传入参数objects数组 // 数组个数和addParameter被调用次数相等,如果没有参数,则不调用addParameter和setReturnType,然后objects长度为0
//xmlRequestStr 这个要和写的webservice的对应方法的入参名称要一样,要不收不到数据
call.addParameter(new QName("xmlRequestStr"), org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN); // 设置返回类型 call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING); System.out.println("请求的报文:"+Str); call.setUseSOAPAction(true); String result = (String) call.invoke(new String[] {Str}); System.out.println("返回的加密报文:"+result); } public static void main(String args[]) throws FileNotFoundException { Document doc = JdomUtil.build(new FileInputStream("D:/1_inSvc.xml")); try { test1(JdomUtil.toString(doc)); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }