所以我创建了一个程序,允许用户在手机上购买公交车票,并在交易完成后立即下载pdf文件。这是通过检查url是否已更改并包含关键字:TicsnetReceipt.aspx让我知道事务已完成来完成的。这样可以正常工作,因为我还会从网址中保存其他信息,例如您的姓名/电子邮件,以备将来使用。
然后我使用Soap下载文件:
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。
在程序崩溃之前,我从envolope获取值,并说:
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;返回有效值。
答案 0 :(得分:0)
由于我没有足够的代表,这应该是一个评论:
如果您的soap呼叫出现异常,请尝试添加以下内容:
catch(Exception e){
Log.e(TAG, "Exception during getting pdf " + e.getMessage());}
所以你实际上可以看到可能发生的事情。
现在,如果你肯定是Soap失败了,你可能想检查一下SoapUI(SoapUI Homepage)里面的soapservice,它也有一个Eclipse插件:Eclipse plugin
您应该尝试在设备上的Web浏览器中访问您的服务。如果它给出一个空白页面,则可能是设备问题或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!