java呼叫WebService介面的一種方法,引數為XML的字串
阿新 • • 發佈:2018-12-10
String xmlinfo = "<data>.......</data>";//xml引數 try { String url = "http://******/Server?wsdl"; Service service = new Service(); Call call = (Call) service.createCall(); call.setTargetEndpointAddress(new java.net.URL(url)); //名稱空間和呼叫介面的方法名 call.setOperationName(new javax.xml.namespace.QName("http://z****.com/", "method")); call.setUseSOAPAction(true); call.addParameter("xmlBody",org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);//可多個.addParameterMode // 設定返回型別 call.setReturnClass(String.class); Object a=""; try { // 使用invoke呼叫方法,Object資料放傳入的引數值(可多個) a = call.invoke(new Object[] {xmlinfo}); } catch (Exception e) { e.printStackTrace(); } System.out.println(a); } catch (Exception e) { e.printStackTrace(); }