欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

超简单AXIS实例 ApacheCC++C#Web 

程序员文章站 2022-05-29 12:44:33
...
简单一个WEB 服务程序的开发

package webservicedemo;

/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/

public class HelloCms {
   /* public HelloCms() {
    }
    public static void main(String[] args) {
        HelloCms helloCms1 = new HelloCms();
        System.out.println(helloCms1.getHello("hukun01"));
    }*/


   public String getHello(String username){
          return "Hello "+username+"超简单AXIS实例
            
    
    
        ApacheCC++C#Web ";
   }

}

以上是服务器端代码


package webservicedemo;

/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import javax.xml.rpc.ParameterMode;

public class ClientCms {
    public static void main(String[] args) {
        ClientCms clientCms1 = new ClientCms();
        clientCms1.getHello();
    }

    public void getHello(){
        try{
             Service service = new Service();
             Call call = ( Call ) service.createCall();
             //////////访问即时发布的Distance服务

             //call.setUsername("root");
             //call.setPassword("root");
             //设置访问点
             call.setTargetEndpointAddress( "http://localhost/axis/services/HelloCms" );
             //设置操作名
             call.setOperationName("getHello");
             //设置入口参数
             call.addParameter( "arg1", XMLType.XSD_STRING, ParameterMode.IN );
             call.setReturnType( XMLType.XSD_STRING );
             //调用服务
             String result="";
             String username="abcd";
             long starttime=System.currentTimeMillis();
             result=(String)call.invoke(new Object[] {username} );
             System.out.println("总共 消耗时间:"+(System.currentTimeMillis()-starttime));
             System.out.println("HelloName  result is:"+result);

        }catch (Exception e){
                System.out.println(e.getMessage());
                System.out.println("###########################");
                e.printStackTrace();
        }
   }

}

以上是客户端代码


<service name="HelloCms" provider="java:RPC">
  <parameter name="allowedRoles" value="*"/>
  <parameter name="className" value="webservicedemo.HelloCms"/>
</service>

以上为服务器server-config.wsdd配置文件