2015-02-06 30 views
0

我正在嘗試調用Web服務以獲取其響應。我使用基於軸的SOAP webservice.But當我運行代碼時,它給了我一個sasxexception。 這是我的Java代碼:org.xml.sax.SAXException:錯誤的信封標記:html

import java.io.BufferedWriter; 
import java.io.File; 
import java.io.FileWriter; 
import java.io.IOException; 

import org.apache.axis.client.Call; 
import org.apache.axis.client.Service; 
import org.apache.axis.encoding.XMLType; 

import javax.xml.namespace.QName; 
import javax.xml.rpc.ParameterMode; 

    public class ClientTest { 

     public static void main(String [] args) 
     { 
      String request = "<Request onErrorAbort=\"yes\">\n"+ 
      "<Service name=\""+service+"\" operation=\""+operation+"\" id=\"11500\">\n"+ 
       "<Parameter name=\"ApplicationExterieureIdentifiant\">"+applicationExterieureIdentifiant+"</Parameter>\n"+ 
       "<Parameter name=\"ApplicationExterieureLibelle\">"+applicationExterieureLibelle+"</Parameter>\n"+ 
       "<Parameter name=\"ActionTypeLibelle\">"+actionTypeLibelle+"</Parameter>\n"+ 
       "<Parameter name=\"ActionIdentifiant\">"+actionIdentifiant+"</Parameter>\n"+ 
       "<Parameter name=\"ActionLibelle\">"+actionLibelle+"</Parameter>\n"+ 
       "<Parameter name=\"PatientIdentifiant\">"+patientIdentifiant+"</Parameter>\n"+ 
       "<Parameter name=\"PatientIPP\">"+patientIPP+"</Parameter>\n"+ 
       "<Parameter name=\"VenueIdentifiant\">"+venueIdentifiant+"</Parameter>\n"+ 
       "<Parameter name=\"VenueNumero\">"+venueNumero+"</Parameter>\n"+ 
       "<Parameter name=\"InterventionIdentifiantExterieur\">"+interventionIdentifiantExterieur+"</Parameter>\n"+ 
       "<Parameter name=\"PrescripteurIdentifiant\">"+prescripteurIdentifiant+"</Parameter>\n"+ 
       "<Parameter name=\"PrescripteurCompteUtilisateur\">"+prescripteurCompteUtilisateur+"</Parameter>\n"+ 
       "<Parameter name=\"PrescripteurNomPrenom\">"+prescripteurNomPrenom+"</Parameter>\n"+ 
       "<Parameter name=\"CreateurIdentifiant\">"+createurIdentifiant+"</Parameter>\n"+ 
       "<Parameter name=\"CreateurCompteUtilisateur\">"+createurCompteUtilisateur+"</Parameter>\n"+ 
       "<Parameter name=\"InterventionMetiers\">"+interventionMetiers+"</Parameter>\n"+ 
       "<Parameter name=\"InterventionPlanificationDate\">"+interventionPlanificationDate+"</Parameter>\n"+ 
       "<Parameter name=\"InterventionPlanificationDansJournee\">"+interventionPlanificationDansJournee+"</Parameter>\n"+ 
       "<Parameter name=\"InterventionPlanificationAuBesoin\">"+interventionPlanificationAuBesoin+"</Parameter>\n"+ 
       "<Parameter name=\"InterventionPlanificationAuBesoinCondition\">"+interventionPlanificationAuBesoinCondition+"</Parameter>\n"+ 
       "<Parameter name=\"InterventionPlanificationDuree\">"+interventionPlanificationDuree+"</Parameter>\n"+ 
       "<Parameter name=\"InterventionPlanificationCommentaire\">"+interventionPlanificationCommentaire+"</Parameter>\n"+ 
       "<Parameter name=\"InterventionPriorite\">"+interventionPriorite+"</Parameter>\n"+ 
       "<Parameter name=\"InterventionURLExterieure\">"+interventionURLExterieure.replaceAll("&", "&amp;")+"</Parameter>\n"+ 
       "<Parameter name=\"InterventionURLExterieureParametres\">"+interventionURLExterieureParametres.replaceAll("&", "&amp;")+"</Parameter>\n"+ 
      "</Service>\n"+ 
     "</Request>\n"; 

      callService(request, args[0]); 
     } 

     public static void callService(String request, String urlDest){ 
      try { 

        /* 
        * urlDest the URL of the destination Web Service  
        */ 


        /* 
        * create a new Service instance 
        */ 
        Service serviceInstance = new Service(); 

        /* 
        * ask the Service to create a call 
        */ 
        Call call = (Call) serviceInstance.createCall(); 


        /* 
        * We tell the Call that this URL is the target endpoint to connect to 
        */ 
        call.setTargetEndpointAddress(new java.net.URL(urlDest)); 

        /* 
        * The QName uses the webservice namespace used in the WSDL file 
        * and the name of the method on the webservice that we want to execute: returnResponse 
        */ 

        call.setOperationName(new QName("http://www.crih-des-alpes.com/PcfwkWebService", "ExecuteString")); 

        /* 
        * we tell the call that we have two input parameters 
        * -- a String followed by another String -- 
        * and that we expect a String to be returned to us. 
        */ 

        call.addParameter("arg0", XMLType.XSD_STRING, ParameterMode.IN); 
        call.addParameter("arg1", XMLType.XSD_STRING, ParameterMode.IN);  
        call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING); 

        System.out.println("before invoke: "+call.toString()); 
        /* 
        * we invoke the Web Service call, passing it our parameters, 
        * wrapping in an Object array, and capture the response 
        */ 
        String response = (String) call.invoke(new Object[] {request ,"CNET_VA_DPLAN_API" });  
        System.out.println("The result : " + response); 
       // createFileResult(ret); 
       } catch (Exception e) { 
        System.err.println(e.toString()); 
       } 
     } 

    } 

任何一個可以幫助我怎樣才能解決這個例外?編寫SOAP客戶端的

回答

0

標準方式包括客戶端生成從WSDL文件

wsimport -keep -verbose http://com.company/ws/server?wsdl 

編碼字符串一切可以工作,但是從長遠來看,你會真的失去了。