webService第一个SimpleService调用getGreeting出现“你好 null”的情况

在网上看到一个以axis2为框架webservice文章http://wenku.baidu.com/view/212d1eebe009581b6bd9eb69.html
我把axis2.war文件复制到tomcat上webapp下,然后启动tomcat后,通过http://localhost:8080/axis2表明web服务引擎发布成功了,
Java code
?
1
2
3
4
5
6
7
8
9
10
11
12
public  class  SimpleService
{
    public  String getGreeting(String name)
    {
         System.out.println( "-----" +name+ "------" );
         return  "您好," +name;
    }
     public  int  getPrice()
     {
        return  new  java.util.Random().nextInt( 1000 );
     }
}

javac SimpleService.java后产生.class文件,然后复制到F:\apache-tomcat-7.0.25\apache-tomcat-7.0.25\webapps\axis2\WEB-INF\pojo下,无参数方法返回正常,但我访问带参数的方法时候
http://localhost:8080/axis2/services/SimpleService/getGreeting?name=bill,信息如下:
XML/HTML code
?
1
2
3
- < ns:getGreetingResponse  xmlns:ns = "http://ws.apache.org/axis2" >
   < return >您好,null</ return
   </ ns:getGreetingResponse >

按照此情况只能解释为name=bill这个参数值没有传过去,后来我又试用java客户端调了一下,成功了
Java code
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import  javax.xml.namespace.QName;
 
import  org.apache.axis2.AxisFault;
import  org.apache.axis2.addressing.EndpointReference;
import  org.apache.axis2.client.Options;
import  org.apache.axis2.rpc.client.RPCServiceClient;
 
import  com.sun.tools.jxc.gen.config.Classes;
 
public  class  RPCClinnt {
 
     public  static  void  main(String[] args)  throws  Exception {
         
         //使用RPC方式调用WebService
         RPCServiceClient serviceClient= new  RPCServiceClient();
         Options options=serviceClient.getOptions();
         //指定调用WebService的URL
         EndpointReference targetERP= new  EndpointReference( "http://localhost:8080/axis2/services/SimpleService" );
         options.setTo(targetERP);
         //指定getGreeting方法的参数值
         Object[] opAddEntryArgs= new  Object[]{ "超人" };
         //指定getGreeting方法返回值的数据类型的Class对象
         Class[] classes= new  Class[] {String. class };
         //指定要调用的getGreeting方法及WSDL文件的命名空间
         QName opAddEntry= new  QName( "http://ws.apache.org/axis2" "getGreeting" );
         //调用getGreeting方法并输出该方法的返回值
         System.out.println(serviceClient.invokeBlocking(opAddEntry, opAddEntryArgs,classes)[ 0 ]);
     }
 
}








成功打印出----您好,超人
为什么在网页上直接传参数暴露的方法不能接受呢,请高手指点一下,谢谢

http://localhost:8080/axis2/services/SimpleService/getGreeting?name=bill这里的参数不一定是name,比如

<xs:element name="sayHello"><xs:complexType><xs:sequence><xs:element minOccurs="0" name="args0" nillable="true" type="xs:string"/></xs:sequence></xs:complexType></xs:element>这里就用args0
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值