Android KSoap Output Error
I've tried to work web service on android but I've taken an error in emulator output:
org.xmlpull.v1.XmlPullParserException:expecteed: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope(position:START_TAG@1:6 in java.io.InputStreamReader@43e567a0)
In here, my code:
package com.webServiceDeneme;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.*;
public class WebServiceDenemeActivity extends Activity {
Button btn;
@Override
public void onCre开发者_如何转开发ate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn=(Button)findViewById(R.id.button1);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String NAMESPACE="http://www.vakifbank.com.tr/";
String METHOD_NAME="faiz-maliyet-oranlari.aspx";
String SOAP_ACTION="http://www.vakifbank.com.tr/faiz-maliyet-oranlari.aspx";
String URL="http://192.168.2.1/VipEvents/Services/BasicServices.asmx";
SoapObject request=new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope=new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(request);
try
{
AndroidHttpTransport aht=new AndroidHttpTransport(URL);
aht.call(SOAP_ACTION, envelope);
SoapPrimitive res=(SoapPrimitive)envelope.getResponse();
btn.setText(res.toString());
}
catch (Exception e) {
// TODO: handle exception
btn.setText(e.toString());
e.printStackTrace();
}
}
});
}}
Any help is appreciated.
Most likely you've received non-SOAP response.
To dump and inspect your SOAP request/response, set aht.debug = true;
, and then after you've called aht.cal(...)
, print values aht.requestDump
and aht.responseDump
to output (like external file or LogCat).
For example:
//...
aht.debug = true;
aht.call(SOAP_ACTION, envelope);
Log.e("SOAP_REQUEST", "----------------------------");
Log.e("SOAP_REQUEST", XmlUtils.format(aht.requestDump));
Log.e("SOAP_REQUEST", "----------------------------");
Log.e("SOAP_RESPONSE", "----------------------------");
Log.e("SOAP_RESPONSE", XmlUtils.format(aht.responseDump));
Log.e("SOAP_RESPONSE", "----------------------------");
Where XmlUtils
class has next code:
public class XmlUtils
{
static public String format(String unformattedXml)
{
StringWriter writer = new StringWriter();
try
{
Document doc = parseXml(unformattedXml);
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
transformer.transform(new DOMSource(doc), new StreamResult(writer));
writer.close();
}
catch(Exception ex)
{
return unformattedXml;
}
return writer.toString();
}
private static Document parseXml(String xml) throws IOException, ParserConfigurationException, SAXException
{
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource is = new InputSource(new StringReader(xml));
return db.parse(is);
}
}
精彩评论