微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Xfire调用webservice无法传递参数问题解决

最近开发Xfire发布调用webservice,发现无法传递参数。

问题出在,发布的webservice接口类需要使用如下这种定义方式

 

package com.demo.service;

import javax.jws.WebParam;

public interface MyService {
  String example(
    @WebParam(targetNamespace = "http://com.demo.service")String agr0,//第一个参数
             @WebParam(targetNamespace = "http://com.demo.service")String agr1,//第二个参数
             @WebParam(targetNamespace = "http://com.demo.service")String agr2,//第三个参数
             @WebParam(targetNamespace = "http://com.demo.service")String agr3//第四个参数,你可以写N个参数
            
  );
}

 

当然,用Xfire调用这个webservice的接口时需要用这种方式

 

 

package com.demo.client;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.soap.soAPBinding;

@WebService(name = "IMyService",targetNamespace = "http://com.demo.service")
@SOAPBinding(use = SOAPBinding.Use.LIteraL,parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)
public interface IMyService {

    @WebMethod(operationName = "example",action = "")
    @WebResult(name = "return",targetNamespace = "http://com.demo.service")
    public String example(
            @WebParam(name = "arg0",targetNamespace = "http://com.demo.service")
            String arg0,//第一个参数
            @WebParam(name = "arg1",targetNamespace = "http://com.demo.service")
            String arg1,//第二个参数
            @WebParam(name = "arg2",targetNamespace = "http://com.demo.service")
            String arg2,//第三个参数
            @WebParam(name = "arg3",targetNamespace = "http://com.demo.service")
            String arg3//第四个参数,后面可以加N个参数自己定
            );
 
 
}

 

然后再使用xfire调用方式,就可以传递参数了

 

 

package com.demo.client;
import java.net.MalformedURLException;

import org.codehaus.xfire.XFire;
import org.codehaus.xfire.XFireFactory;
import org.codehaus.xfire.client.Client;
import org.codehaus.xfire.annotations.AnnotationServiceFactory;
import org.codehaus.xfire.client.XFireProxyFactory;
import org.codehaus.xfire.service.Service;

 public class Test {
  public static void main(String[] args) throws MalformedURLException {

         String serviceUrl = "http://localhost:8080/Demo/services/MyService";
        
         Service serviceModel = new AnnotationServiceFactory().create(IMyService.class);
        
         XFire xFire = XFireFactory.newInstance().getXFire();
         XFireProxyFactory serviceFactory = new XFireProxyFactory(xFire);
        
         try {
          IMyService service = (IMyService) serviceFactory.create(serviceModel,
                     serviceUrl);
             String hello = service.example("001","002","003","004");

             System.out.println(hello);
         } catch (Exception e) {
             e.printstacktrace();
         }
       
     }
 }

 

 

demo源码下载:http://download.csdn.net/detail/zongkai2012/5992713

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐