怎样调用web service ? 怎样调用web service 啊?有几种方式哦?哪个有完整点的文档,发来看看啊,谢谢。我qq:570342986 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 package com.paytong.ah2;import java.net.URL;import javax.xml.namespace.QName;import javax.xml.rpc.ParameterMode;import org.apache.axis.client.Call;import org.apache.axis.encoding.ser.BeanDeserializerFactory;import org.apache.axis.encoding.ser.BeanSerializerFactory;import com.sea.ws.passportstub.Insert;import com.sea.ws.passportstub.InsertService;import com.sea.ws.passportstub.InsertServiceLocator;import com.sea.ws.passportstub.Person;//import com.sun.org.apache.xml.internal.utils.QName;//import com.sun.org.apache.xerces.internal.xni.QName;public class Ah2_test { public static void main(String[] args) { InsertService service = new InsertServiceLocator(); try { Person p = new Person(); p.setName("jack"); p.setPassword("123456"); // Insert client = service.getInserttttt(); // client.insert(p); String endpoint = "http://localhost:8080/axis/services/Inserttttt"; Call call = (Call)service.createCall(); javax.xml.namespace.QName qname = new javax.xml.namespace.QName("urn:BeanService", "Person"); call.registerTypeMapping(Person.class, qname, new BeanSerializerFactory(Person.class, qname), new BeanDeserializerFactory(Person.class, qname)); call.setTargetEndpointAddress(new URL(endpoint)); //调用的服务器端方法 call.setOperationName(new QName("Inserttttt", "insert")); //设定传入的参数,这里qname即Person.class call.addParameter("arg1", qname, ParameterMode.IN); //设定返回的参数是Order.class call.setReturnType(qname, Person.class); p = (Person)call.invoke(new Object[] {p}); System.out.println(p.getId()); } catch (Exception e) { e.printStackTrace(); } }} 在Myeclipse中的帮助中就有现成的代码范例public static void main(String[] args) { Service srvcModel = new ObjectServiceFactory().create(IHelloWorldService.class); XFireProxyFactory factory = new XFireProxyFactory(XFireFactory.newInstance().getXFire()); String helloWorldURL = "http://localhost:8080/HelloWorld/services/HelloWorldService"; try { IHelloWorldService srvc = (IHelloWorldService)factory.create(srvcModel, helloWorldURL); String result = srvc.example("hello world"); System.out.print(result); } catch (MalformedURLException e) { e.printStackTrace(); } } public static void main(String[] args) { Service srvcModel = new ObjectServiceFactory().create(IHelloWorldService.class); XFireProxyFactory factory = new XFireProxyFactory(XFireFactory.newInstance().getXFire()); String helloWorldURL = "http://localhost:8080/HelloWorld/services/HelloWorldService"; try { IHelloWorldService srvc = (IHelloWorldService)factory.create(srvcModel, helloWorldURL); String result = srvc.example("hello world"); System.out.print(result); } catch (MalformedURLException e) { e.printStackTrace(); } } 如果我远程调用时,不知道该接口呢? 新手问个XML小问题请高手指教 请教OpenGTS的接受数据的问题! 上下两个frame内容对齐问题 oracle--jdbc问题 在图片存放路径中怎么样获取图片的名字? javabean中调用javabean的问题 jsp servlet 如何快速生成动态页面?求简单方法! 求助 取前台值的时候 struts2进不到set方法 一个比较怪的问题! [在线等待]继续求sqlserver7 jdbc驱动 hibernate启动时自动添加外键 如何判断hibernate从数据库中获取的对象是否为空,若为空,改怎么处理?
import java.net.URL;import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;import org.apache.axis.client.Call;
import org.apache.axis.encoding.ser.BeanDeserializerFactory;
import org.apache.axis.encoding.ser.BeanSerializerFactory;import com.sea.ws.passportstub.Insert;
import com.sea.ws.passportstub.InsertService;
import com.sea.ws.passportstub.InsertServiceLocator;
import com.sea.ws.passportstub.Person;
//import com.sun.org.apache.xml.internal.utils.QName;
//import com.sun.org.apache.xerces.internal.xni.QName;public class Ah2_test { public static void main(String[] args) {
InsertService service = new InsertServiceLocator();
try {
Person p = new Person();
p.setName("jack");
p.setPassword("123456");
// Insert client = service.getInserttttt();
// client.insert(p);
String endpoint = "http://localhost:8080/axis/services/Inserttttt";
Call call = (Call)service.createCall();
javax.xml.namespace.QName qname = new javax.xml.namespace.QName("urn:BeanService", "Person");
call.registerTypeMapping(Person.class, qname, new BeanSerializerFactory(Person.class, qname),
new BeanDeserializerFactory(Person.class, qname));
call.setTargetEndpointAddress(new URL(endpoint));
//调用的服务器端方法
call.setOperationName(new QName("Inserttttt", "insert"));
//设定传入的参数,这里qname即Person.class
call.addParameter("arg1", qname, ParameterMode.IN);
//设定返回的参数是Order.class
call.setReturnType(qname, Person.class);
p = (Person)call.invoke(new Object[] {p});
System.out.println(p.getId());
} catch (Exception e) {
e.printStackTrace();
} }}
Service srvcModel = new ObjectServiceFactory().create(IHelloWorldService.class);
XFireProxyFactory factory = new XFireProxyFactory(XFireFactory.newInstance().getXFire());
String helloWorldURL = "http://localhost:8080/HelloWorld/services/HelloWorldService";
try {
IHelloWorldService srvc = (IHelloWorldService)factory.create(srvcModel, helloWorldURL);
String result = srvc.example("hello world");
System.out.print(result);
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
Service srvcModel = new ObjectServiceFactory().create(IHelloWorldService.class);
XFireProxyFactory factory = new XFireProxyFactory(XFireFactory.newInstance().getXFire());
String helloWorldURL = "http://localhost:8080/HelloWorld/services/HelloWorldService";
try {
IHelloWorldService srvc = (IHelloWorldService)factory.create(srvcModel, helloWorldURL);
String result = srvc.example("hello world");
System.out.print(result);
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
如果我远程调用时,不知道该接口呢?