1

所以我创建了一个程序,允许用户在手机上购买巴士票,并在交易完成后立即下载 pdf 文件。这是通过检查 url 是否已更改并包含关键字来完成的:TicsnetReceipt.aspx 让我知道交易已完成。这很好用,因为我还保存了其他信息,例如来自 url 的姓名/电子邮件以供将来使用。

然后我使用肥皂下载文件:

public String getPDFxml(String ReferenceID){
    String NAMESPACE = "http://tempuri.org/";
    String METHOD_NAME = "GetPDFxml";
    String SOAP_ACTION = "http://tempuri.org/GetPDFxml";
    String URL = "http://77.40.188.73:28082/SasMobileWS/SasMobile.asmx?op=GetPDFxml";

    try {

        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

        PropertyInfo pi = new PropertyInfo();
        pi.setName("Reference");
        pi.setValue(ReferenceID);
        request.addProperty(pi);

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet=true;
        envelope.setOutputSoapObject(request);

        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

        androidHttpTransport.call(SOAP_ACTION, envelope);

        SoapPrimitive result = (SoapPrimitive)envelope.getResponse();
        String strRes = result.toString();
        String temp[];
        temp = strRes.split("TravelDate");
        String Date[] = temp[1].split(">|<|/");
        String theDate = Date[1];
        return(theDate);
    } catch (IOException e) {
        e.printStackTrace();
    } catch (XmlPullParserException e) {
        e.printStackTrace();
    }
    return null;
}


public void getPDFbytes(String TransactionID, String Date){
    String NAMESPACE = "http://tempuri.org/";
    String METHOD_NAME = "GetPDFbytes";
    String SOAP_ACTION = "http://tempuri.org/GetPDFbytes";
    String URL = "http://77.40.188.73:28082/SasMobileWS/SasMobile.asmx?op=GetPDFbytes";

    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

    PropertyInfo pi = new PropertyInfo();
    pi.setName("Reference");
    pi.setValue(TransactionID);
    request.addProperty(pi);

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet=true;
    envelope.setOutputSoapObject(request);

    try {
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
        androidHttpTransport.call(SOAP_ACTION, envelope);
    } catch (Exception e) {
        e.printStackTrace();
    }

    SoapObject resultsRequestSOAP = null;
    try{
        resultsRequestSOAP = (SoapObject) envelope.getResponse();
    }catch (Exception e) {
        try{    
        resultsRequestSOAP = (SoapObject) envelope.bodyIn; 
        }catch(Exception f){
            f.printStackTrace();
        }
    } 
    byte[] result = null;
    try {
        result = Base64.decode(resultsRequestSOAP.getProperty("GetPDFbytesResult").toString());
    } catch(Exception e){
        e.printStackTrace();
    }
    try {
        Date = Date.replace(".", "");
        FileOutputStream fos = openFileOutput(Date + "_" + TransactionID + ".pdf", Context.MODE_WORLD_READABLE);

        fos.write(result);
        fos.close();

    } catch(FileNotFoundException ex){
        ex.printStackTrace();
    } catch(IOException ioe){
        ioe.printStackTrace();
    }
}

这一切在我尝试过的其他模型上都可以正常工作,但在 S3 上,它不会下载文件,并在用户尝试在查看器中打开文件时告诉用户该文件不存在。

我 99% 确定肥皂有问题,我只是想不通。但是,如果这看起来不错,那么我不知道发生了什么:p

提前致谢 :)

在做了更多测试后,我知道问题来自:

  androidHttpTransport.call(SOAP_ACTION, envelope);

这似乎根本不会读取数据,这很奇怪,因为它应该与上述方法中的输入相同。两种方法都接受一个字符串 Reference(实际上是一个数字),第一个方法 GetPDFxml 返回一个字符串,GetPDFbytes 返回 base64Binary。

就在程序崩溃之前,我从信封获取值,它说:

envelope    
SoapSerializationEnvelope  (id=830066090736)    
addAdornments   true    
avoidExceptionForUnknownProperty    false   
bodyIn  SoapFault  (id=830066150416)    
bodyOut SoapObject  (id=830066090472)   
classToQName    Hashtable  (id=830066090944)    
dotNet  true    
enc "http://schemas.xmlsoap.org/soap/encoding/" (id=830065748280)   
encodingStyle   null    
env "http://schemas.xmlsoap.org/soap/envelope/" (id=830065748552)   
headerIn    null    
headerOut   null    
idMap   Hashtable  (id=830066090864)    
implicitTypes   false   
multiRef    Vector  (id=830066102400)   
properties  Hashtable  (id=830066090824)    
qNameToClass    Hashtable  (id=830066090904)    
version 110 
xsd "http://www.w3.org/2001/XMLSchema" (id=830065748824)    
xsi "http://www.w3.org/2001/XMLSchema-instance" (id=830065749064)   

然后既不是信封.getResponse(); 或 resultsRequestSOAP = (SoapObject) 信封.bodyIn;返回一个有效值。

4

1 回答 1

0

由于我没有足够的代表,这应该是一个评论:

如果您的肥皂调用弹出异常,请尝试添加以下内容:

catch(Exception e){
Log.e(TAG, "Exception during getting pdf " + e.getMessage());} 

所以你实际上可以看到可能发生的事情。

现在,如果您确定这是 Soap 失败,您可能需要检查 SoapUI( SoapUI 主页)中的 soapservice ,它也有一个 Eclipse 插件:Eclipse plugin

您应该尝试在设备上的网络浏览器中访问您的服务。如果它给出一个空白页,它要么是设备问题,要么是 IIS 问题。

附带说明;我个人对我的SoapSerializationEnvelope(SoapEnvelope.VER11)号码有问题。


您可以为调试添加的内容是:

 SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.setOutputSoapObject(request);
    envelope.dotNet = true;
    Log.d("SoapBody",envelope.bodyOut.toString()); //This

    HttpTransportSE httpTransport = new HttpTransportSE(URL);
    httpTransport.debug = true; //And this!
于 2012-11-07T09:43:15.980 回答