怎样调用web service 啊?有几种方式哦?哪个有完整点的文档,发来看看啊,谢谢。
我qq:570342986

解决方案 »

  1.   

    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();
    } }}
      

  2.   

    在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();     
     } 
      

  3.   

    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();    



    如果我远程调用时,不知道该接口呢?