用Axis开发Web Service的三种部署方式测试

来源:互联网 发布:wampserver php.ini 编辑:程序博客网 时间:2024/05/17 18:03

package com.norteksoft.casc;

import gongya.SoapSever.Hello_jws.HelloService;
import gongya.SoapSever.Hello_jws.HelloServiceLocator;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;

import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceException;


import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.client.ServiceFactory;

public class Bussines
{

 public static String  DII(String name)
 {
  
  String endPoint="http://gongya/SoapSever/Hello.jws";
  String rv="";
  Service service=new Service();
  Call call=null;
  try
  {
   call=(Call) service.createCall();
   call.setOperationName(new QName(endPoint,"test"));
   call.setTargetEndpointAddress(new URL(endPoint));
        rv=(String) call.invoke(new Object[] {name});
           
  }
  
   catch (RemoteException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
  catch (ServiceException e) {
   
   e.printStackTrace();
  }
  catch (MalformedURLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  
   return rv;
 }
 
 
 public static String dproxy(String name)
 {
  String wsdlURl="http://gongya/SoapSever/Hello.jws?wsdl";
  
  String  naspaceURL="http://gongya/SoapSever/Hello.jws";
  
  String portName="Hello";
  String serviceName="HelloService";
  
 try  
 {
  QName pName=new QName(naspaceURL, portName); 
  QName sName=new QName(naspaceURL, serviceName);
  
  javax.xml.rpc.ServiceFactory  serviceFactory = (ServiceFactory) ServiceFactory.newInstance();
        javax.xml.rpc.Service service=serviceFactory.createService(new URL(wsdlURl),sName);
        SoapClientInterface proxy=(SoapClientInterface) service.getPort(pName,SoapClientInterface.class);
     
        return proxy.test(name);
       
   
 }
  catch (Exception e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
    
 return "";    
   
 }
 
 public static String stubs(String name)
 {
  
  HelloServiceLocator helloLocal=new HelloServiceLocator();
  try
  {
   return helloLocal.getHello().test(name);
  }
  catch (RemoteException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (ServiceException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  return "";
 }
 // Hello hello;
 
 
 
  public  static void  main  (String[] args)
  {
   HelloService hello=new HelloServiceLocator();
   char[] temp=new char[100];
   int i=0;
  
   while(true)
   {
  
  try {
   
   
   int c=System.in.read();
    if(c!='/n'&&c!=' ')
    {
     temp[i++]=(char) c;
    }
    else
    {
    
     String name=new String(new String(temp,0,i-1).getBytes("ISO8859_1"),"GBK");
     if("exit".equalsIgnoreCase(name))
     {
      System.out.println("bye");
      System.exit(0);
     
     }
    
     System.out.print(Bussines.stubs(name));
    // System.out.println("/n");
    //System.out.println("/n");
     i=0;
    }
  }
  catch (IOException e1)
  {
   // TODO Auto-generated catch block
   e1.printStackTrace();
  }
  
   }
   
  }
 
 
}

原创粉丝点击