So i've created a program that allows the users to buy a bus ticket on their phones, and download a pdf file as soon as the transaction is finished. This is done by checking if the url has changed and contains the keyword: TicsnetReceipt.aspx letting me know that the transaction is done. This works fine as i also save other information like your name/email from the url for future use.
Then i use Soap to download the file:
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();
}
}
This all works fine on the other models i've tried on, but on S3 it just won't download the file and tells the user the file doesn't exist when he tries to open it in the viewer.
I'm 99% sure it's something wrong with soap that i just can't figure out. But if this looks fine then i have no clue what's going on :p
Thanks in advance :)
After doing a bit more testing i know that the problem comes from:
androidHttpTransport.call(SOAP_ACTION, envelope);
which won't seem the read the data at all, which is weird since it's supposed to be the same input as in the method above. Both methods accept a string Reference (which is really a number) And the first one, GetPDFxml returns a string and GetPDFbytes returns base64Binary.
just before the program crashes i get the values from envolope and it says:
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)
And then neither envelope.getResponse(); or resultsRequestSOAP = (SoapObject) envelope.bodyIn; returns a valid value.
Since I don't have enough rep, this should be a comment:
If your soap call pops an exception, try adding something like :
catch(Exception e){
Log.e(TAG, "Exception during getting pdf " + e.getMessage());}
So you can actually see what might be happening.
Now if your positive that it's the Soap failing, you might want to check your soapservice inside SoapUI (SoapUI Homepage) which also has a Eclipse plugin : Eclipse plugin
And you should try to access your service inside the webbrowser on the device. If it gives a blank page, it's either a device problem or an IIS problem.
On a side note; I personally had problems with my SoapSerializationEnvelope(SoapEnvelope.VER11)
number.
Things you could add for debugging is:
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!