深爱甜蜜 2018-08-09 08:35 采纳率: 50%
浏览 8588
已采纳

webservice调用时怎么传参数

<?xml version="1.0" encoding="UTF-8"?>

-

-

-xsd:schema

/xsd:schema

-

-

-

-

-

-

-

-

-

-

下面是我的调用代码:

 Service service = new Service();
        Call call = (Call) service.createCall();
        String url = "http://192.1.1.64:8082/Service/ServiceHello?wsdl";
        call.setTargetEndpointAddress(url);
        call.setOperationName(new QName("http://webservice_302/", "getValue"));
        call.addParameter(new QName("http://webservice_302/", "name"), org.apache.axis.encoding.XMLType.XSD_STRING,
                javax.xml.rpc.ParameterMode.IN);
        call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
        String result = (String) call.invoke(new String[] { "11" });
        System.out.println(result);

下面是接口的方法点:

 public String getValue(String name){
        return "欢迎你! "+name;
    }

可以成功调用,返回结果是:欢迎你! null

说明参数没有传进去,请问这里我应该怎么写呢?

  • 写回答

5条回答 默认 最新

  • xcgh 2018-08-09 09:10
    关注

    入参类型应该是org.apache.axis.Constants.XSD_STRING,不认为是org.apache.axis.encoding.XMLType.XSD_STRING

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
  • 深爱甜蜜 2018-08-09 08:39
    关注
    
    <?xml version="1.0" encoding="UTF-8"?><!-- Published by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e. --><!-- Generated by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e. --><definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://webservice_302/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://webservice_302/" name="HelloService">
    <types>
    <xsd:schema>
    <xsd:import namespace="http://webservice_302/" schemaLocation="http://192.1.1.64:8082/Service/ServiceHello?xsd=1"></xsd:import>
    </xsd:schema>
    </types>
    <message name="getValue">
    <part name="parameters" element="tns:getValue"></part>
    </message>
    <message name="getValueResponse">
    <part name="parameters" element="tns:getValueResponse"></part>
    </message>
    <portType name="Hello">
    <operation name="getValue">
    <input wsam:Action="http://webservice_302/Hello/getValueRequest" message="tns:getValue"></input>
    <output wsam:Action="http://webservice_302/Hello/getValueResponse" message="tns:getValueResponse"></output>
    </operation>
    </portType>
    <binding name="HelloPortBinding" type="tns:Hello">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"></soap:binding>
    <operation name="getValue">
    <soap:operation soapAction=""></soap:operation>
    <input>
    <soap:body use="literal"></soap:body>
    </input>
    <output>
    <soap:body use="literal"></soap:body>
    </output>
    </operation>
    </binding>
    <service name="HelloService">
    <port name="HelloPort" binding="tns:HelloPortBinding">
    <soap:address location="http://192.1.1.64:8082/Service/ServiceHello"></soap:address>
    </port>
    </service>
    </definitions>
    
    评论
  • qq_35280588 2018-08-09 08:54
    关注

    public static String rpcCall(String serverName, Object[] parameters) throws AxisFault {
    RPCServiceClient serviceClient = new RPCServiceClient();
    EndpointReference targetEPR = new EndpointReference(Constant.WEB_SERVICE_WSDL_URL);
    Options options = serviceClient.getOptions();
    options.setManageSession(true);
    options.setProperty(HTTPConstants.REUSE_HTTP_CLIENT,true);
    options.setTo(targetEPR);
    options.setAction("urn:"+serverName);
    QName qname = new QName(Constant.NAME_SPACE, serverName);
    OMElement element = serviceClient.invokeBlocking(qname, parameters);
    String result = element.getFirstElement().getText();
    serviceClient.cleanupTransport();
    return result;
    }

    评论
  • qq_35280588 2018-08-09 08:56
    关注

    /**
    * 服务调用
    * @param serverName 服务名称
    * @param parameters 业务参数(接口中规定的方法的参数)
    * @return
    * @throws AxisFault
    */
    public static String rpcCall(String serverName, Object[] parameters) throws AxisFault {
    //使用rpc方式调用webService
    RPCServiceClient serviceClient = new RPCServiceClient();
    //调用指定webService的url
    EndpointReference targetEPR = new EndpointReference(Constant.WEB_SERVICE_WSDL_URL);
    Options options = serviceClient.getOptions();
    //客户端开启session对话管理
    options.setManageSession(true);
    options.setProperty(HTTPConstants.REUSE_HTTP_CLIENT,true);
    //确定目标服务地址
    options.setTo(targetEPR);
    //确定调用方法
    options.setAction("urn:"+serverName);
    //指定接口的命名空间和调用的方法名
    QName qname = new QName(Constant.NAME_SPACE, serverName);
    //调用方法传递参数 调用服务 获取服务返回的结果集
    OMElement element = serviceClient.invokeBlocking(qname, parameters);
    //返回结果就是由一段OMElement对象封装的xml字符串
    //我们可以对之灵活应用,下面我取第一个元素值,并打印之,因为调用的方法返回一个结果
    String result = element.getFirstElement().getText();
    serviceClient.cleanupTransport();
    return result;
    }

    评论
  • 卡哇伊程序员 2018-08-09 09:09
    关注

    https://download.csdn.net/download/qq_34346915/10593706 里面有全套的接口生成以及调用

    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 初学者c语言题目解答
  • ¥15 div editable中的光标问题
  • ¥15 mysql报错1415Not allowed to return a result set from a trigger 不知如何修改
  • ¥60 Python输出Excel数据整理,算法较为复杂
  • ¥15 回答几个问题 关于数据库
  • ¥15 51单片机串口通信问题,未完成且要修改
  • ¥15 百鸡问题 c++编程问题(相关搜索:输出数据)
  • ¥30 如何在CMD中设置代理
  • ¥15 我有一块薛定谔的硬盘
  • ¥15 微信小游戏开发2D碰撞检测问题