加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-17 00:08:56 所属栏目:安全 来源:网络整理
导读:最近开发Xfire发布调用webservice,发现无法传递参数。 问题出在,发布的webservice接口类需要使用如下这种定义方式 ? package com.demo.service; import javax.jws.WebParam; public interface MyService { ? String example( ??? @WebParam(targetNamespac

最近开发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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读