使用这种方式要注意,具体的WebService实现代码要放在App_Data下,而且Service.asmx与Service.asmx.cs文件是分开的才能正常传参数,否则方法可以调到,但是参数传不到
import java.net.URL; import org.codehaus.xfire.client.Client; public class Test { public static void main(String[] args) { try { Client client = new Client(new URL("http://192.168.10.76/Servicetcl.asmx?wsdl")); Object[] results = client.invoke("addRecordInfo", new String[]{"1","C0000020","2012-03-08 12:34:56","2012-08-09 04:45:59","953077e36426cf3af9676a475b23e2ac"}); System.out.println(results[0]); } catch (Exception e) { e.printStackTrace(); } } }
2.axis方式
axis方式就没有上边XFire的情况,Service.asmx与Service.asmx.cs可以是一体的
import org.apache.axis.client.Call; import org.apache.axis.client.Service; public class testnetservice { public testnetservice() { } public static void main(String[] args) { try { Integer i = new Integer(1); Integer j = new Integer(2); String endpoint = "http://localhost:2010/Service.asmx"; Service service = new Service(); Call call = (Call) service.createCall(); call.setTargetEndpointAddress(new java.net.URL(endpoint)); call.setOperationName(new QName("http://www.my.com/su", "intadd")); call.addParameter("a", org.apache.axis.encoding.XMLType.XSD_DATE, javax.xml.rpc.ParameterMode.IN); call.addParameter("b", org.apache.axis.encoding.XMLType.XSD_DATE, javax.xml.rpc.ParameterMode.IN); call.setReturnType(org.apache.axis.encoding.XMLType.XSD_INT); call.setUseSOAPAction(true); call.setSOAPActionURI("http://www.my.com/rpc"); Integer k = (Integer) call.invoke(new Object[] { i, j }); System.out.println("result is " + k.toString() + "."); } catch (Exception e) { System.err.println(e.toString()); } } }
黑色头发:http://heisetoufa.iteye.com/