0

我创建了 5 种不同类型的服务。A、B、C、D、E。使用 Apache 轴

从单个 java 客户端,我将调用所有这 5 个服务,并为每个服务提供 3 个参数。

我创建了客户端。像这样对吗?

import javax.xml.namespace.QName;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;

public class ServicesCaller 
{

    String A="";
    String B="";
    String C="";

    public void services(String start,String end,String comfort)
    {
         try 
         {
            String endpoint1="http://localhost:8080/callser/services/A1";
            String endpoint2="http://localhost:8080/callser/services/A2";
            String endpoint3="http://localhost:8080/callser/services/A3";
            String endpoint4="http://localhost:8080/callser/services/A4";
            String endpoint5="http://localhost:8080/callser/services/A5";

            Service service=new Service();

            Call call=(Call)service.createCall();

            call.setTargetEndpointAddress(new java.net.URL(endpoint1));
            call.setTargetEndpointAddress(new java.net.URL(endpoint2));
            call.setTargetEndpointAddress(new java.net.URL(endpoint3));
            call.setTargetEndpointAddress(new java.net.URL(endpoint4));
            call.setTargetEndpointAddress(new java.net.URL(endpoint5));

            call.setOperationName(new QName("http://service.com","firstReturn"));

            String ret = (String) call.invoke( new Object[] {start,end,comfort} );

         }

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

这是对的吗?当我从我的 jsp 运行时,我得到了这个异常

org.xml.sax.SAXException: Deserializing parameter 'arg0':  could not find deserializer for type {http://schemas.xmlsoap.org/soap/encoding/}string
4

1 回答 1

0

首先,使用 IDE 为每个 Web 服务 WSDL 创建 subs。有了存根之后,只需调用它们的虚拟方法即可。这为您节省了很多时间和精力。

其次使用下面的代码逻辑,根据您的代码,您将无法调用所有 WS,而只能调用最后一个。

如果您没有 IDE,则下载 Net Beans 或 oracle Jdev,它们都是免费软件,如果您不能这样做,则不需要许可证,即使 WSImport 是您拥有的最佳选择。

public class ServicesCaller 
{

    String A="";
    String B="";
    String C="";

    public void services(String start,String end,String comfort)
    {
         try 
         {
            String endpoint1="http://localhost:8080/callser/services/A1";
            String endpoint2="http://localhost:8080/callser/services/A2";
            String endpoint3="http://localhost:8080/callser/services/A3";
            String endpoint4="http://localhost:8080/callser/services/A4";
            String endpoint5="http://localhost:8080/callser/services/A5";

            Service service=new Service();

            Call call=(Call)service.createCall();

            String ret ="";
            call.setOperationName(new QName("http://service.com","allepyReturn"));

            call.setTargetEndpointAddress(new java.net.URL(endpoint1));
            ret = (String) call.invoke( new Object[] {start,end,comfort} );

            call.setTargetEndpointAddress(new java.net.URL(endpoint2));
            ret = (String) call.invoke( new Object[] {start,end,comfort} );

            call.setTargetEndpointAddress(new java.net.URL(endpoint3));
            ret = (String) call.invoke( new Object[] {start,end,comfort} );

            call.setTargetEndpointAddress(new java.net.URL(endpoint4));
            ret = (String) call.invoke( new Object[] {start,end,comfort} );

            call.setTargetEndpointAddress(new java.net.URL(endpoint5));
            ret = (String) call.invoke( new Object[] {start,end,comfort} );

         }

         catch(Exception e)
         {
             System.out.println(e);
         }
    }
于 2013-03-05T20:59:08.657 回答