How to access SOAP web services in Android
I tried to access soap Ws using httpPost;this my code
HttpPost httpPost=new HttpPost(WebService Url);
开发者_运维技巧 httpPost.addHeader("Content-Type", "application/soap+xml; charset=utf-8");
httpPost.addHeader("Host", HostName);
//get from the getflashinfo method;
String soapRequestXml=getFlashInfo(0);
Log.d("Message12", soapRequestXml);
try
{
StringEntity se=new StringEntity(soapRequestXml, HTTP.UTF_8);
se.setContentType("text/xml");
httpPost.setEntity(se);
HttpClient hC=new DefaultHttpClient();
HttpResponse reponse=hC.execute(httpPost);
Log.d("Message12", response.toString());
}
catch (ClientProtocolException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
Second Function
String getFlashInfo(int target)
{
String sHeaderRequest="<s:Envelope xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:a=\"http://www.w3.org/2005/08/addressing\">"+
"<s:Header>" +
"<a:Action s:mustUnderstand=\"1\">http://tempuri.org/IFlashInfoService/GetFlashInfo</a:Action>" +
"<a:ReplyTo><a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address></a:ReplyTo>" +
"<a:To s:mustUnderstand=\"1\">URL</a:To>" +
"</s:Header>" +
"<s:Body xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
"<GetIdTargetRequest xmlns=\"http://tempuri.org/\">" ;
String sHeaderRequest1;
if (target > 0)
{
sHeaderRequest1="<IdTarget>"+" "+target+" "
+"</IdTarget>";
}
else
{
sHeaderRequest1="<IdTarget>0</IdTarget>";
}
sHeaderRequest=sHeaderRequest+sHeaderRequest1;
sHeaderRequest=sHeaderRequest+"</GetIdTargetRequest>";
sHeaderRequest=sHeaderRequest+"</s:Body>";
sHeaderRequest=sHeaderRequest+"</s:Envelope>";
Log.d("Message12", sHeaderRequest);
return sHeaderRequest;
}
I got Null Pointer exception when try to log the reponse message
I used Ksop library with
got some kind of xmlparse error and unknown source exception
Please Help me
Regards, Kariyachan
I am posting a video tutorial, this might help
http://www.vimeo.com/9633556
Happy Coding!
精彩评论