簡體   English   中英

如何使用我的客戶的Web服務?

[英]How to consume web service from my client?

我創建了5種不同類型的服務。 A,B,C,D,E 使用Apache Axis

從單個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

首先,使用IDE為每個Web服務WSDL創建子項。 擁有存根之后,只需調用其虛擬方法即可。 這樣可以節省大量時間和精力。

其次,使用以下代碼邏輯,根據您的代碼,您將無法調用所有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);
         }
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM