首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在三星Galaxy 3上使用Soap下载PDF

在三星Galaxy 3上使用Soap下载PDF
EN

Stack Overflow用户
提问于 2012-11-07 17:21:49
回答 1查看 587关注 0票数 1

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

然后我使用Soap下载文件:

代码语言:javascript
复制
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%确定是soap出了什么问题,我就是搞不清楚。但如果这看起来很好,那么我不知道发生了什么:p

提前感谢:)

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

代码语言:javascript
复制
  androidHttpTransport.call(SOAP_ACTION, envelope);

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

就在程序崩溃之前,我从envolope获得了值,它说:

代码语言:javascript
复制
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)   

然后,envelope.getResponse();或resultsRequestSOAP = (SoapObject) envelope.bodyIn;都不会返回有效值。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-11-07 17:43:16

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

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

代码语言:javascript
复制
catch(Exception e){
Log.e(TAG, "Exception during getting pdf " + e.getMessage());} 

所以你可以真正看到可能发生的事情。

现在,如果您确信是Soap失败了,那么您可能需要检查SoapUI (SoapUI Homepage)中的soapservice,它也有一个Eclipse插件:Eclipse plugin

您应该尝试在设备上的try浏览器中访问您的服务。如果出现空白页,则可能是设备问题或IIS问题。

顺便说一句,我个人的SoapSerializationEnvelope(SoapEnvelope.VER11)号码有问题。

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

代码语言:javascript
复制
 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!
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13266634

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档