Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to create SOAP request via ksoap2
    text
    copied!<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"&gt; &lt;S:Header/&gt; &lt;S:Body&gt; &lt;ns2:FReadStatus xmlns:ns2="http://poweb13/"&gt; &lt;arg0&gt;000D6F0000&lt;/arg0&gt; &lt;/ns2:FReadStatus&gt; &lt;/S:Body&gt; &lt;/S:Envelope&gt; </code></pre> <p>i'm working in an android project which i want to consume some JAX-WS. The services are made by someone else so i can't change anything of them.I want to sent the above SOAP message with this written code but the only thing i receive when call them is java.lang.NullPointerException</p> <pre><code>private static final String NAMESPACE = "http://poweb13/"; private static final String URL = "http://smart.gr:8080/aWESoME/SmartPlugService?wsdl"; private static final String SOAP_ACTION = "SmartPlugService"; private static final String METHOD_NAME = "FReadStatus"; SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); PropertyInfo p1 = new PropertyInfo(); p1.setName("MAC"); p1.setValue("000D6F0000"); p1.setType(myDevice.getmac().toString().getClass()); request.addProperty(p1); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.setOutputSoapObject(request); HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); try { androidHttpTransport.setXmlVersionTag("&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;"); androidHttpTransport.call(SOAP_ACTION, envelope); SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn; String result=resultsRequestSOAP.getProperty("return").toString(); Log.i("info","Received :" + result); } catch (java.lang.ClassCastException e){ SoapFault fault=(SoapFault)envelope.bodyIn; Log.e("error","Received :" + fault.getMessage().toString()); Log.e("error","Received :" + fault.getLocalizedMessage().toString()); StackTraceElement[] st=fault.getStackTrace(); for(int i=0;i&lt;st.length;i++){ Log.e("error","Received :" +st[i] ); } } catch (Exception e) { Log.e("error","smthing went wrong!!"); e.printStackTrace(); } </code></pre> <p>I think that it doesn't create a xml document even, but i don't know how to check it. I tried to create a XmlSerializer to put data for creating xml but i also receive a NullPointerException. So can anyone help me about how to code the above request? here's some parts of wsdl file</p> <pre><code>&lt;definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://poweb13/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://poweb13/" name="SmartPlugService"&gt; &lt;types&gt; &lt;xsd:schema&gt; &lt;xsd:import namespace="http://poweb13/" schemaLocation="http://smart.gr:8080/aWESoME/SmartPlugService?xsd=1"/&gt; &lt;/xsd:schema&gt; &lt;/types&gt; &lt;message name="FReadStatus"&gt; &lt;part name="parameters" element="tns:FReadStatus"/&gt; &lt;/message&gt; ... &lt;portType name="SmartPlugService"&gt; &lt;operation name="FReadStatus"&gt; ... &lt;input wsam:Action="http://poweb13/SmartPlugService/FReadStatusRequest" message="tns:FReadStatus"/&gt; &lt;output wsam:Action="http://poweb13/SmartPlugService/FReadStatusResponse" message="tns:FReadStatusResponse"/&gt; &lt;fault message="tns:InvalidDeviceAddressException" name="InvalidDeviceAddressException" wsam:Action="http://poweb13/SmartPlugService/FReadStatus/Fault/InvalidDeviceAddressException"/&gt; &lt;fault message="tns:InternalServiceException" name="InternalServiceException" wsam:Action="http://poweb13/SmartPlugService/FReadStatus/Fault/InternalServiceException"/&gt; ... &lt;/operation&gt; &lt;/portType&gt; &lt;binding name="SmartPlugServicePortBinding" type="tns:SmartPlugService"&gt; &lt;soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/&gt; ... &lt;operation name="FReadStatus"&gt; &lt;soap:operation soapAction=""/&gt; &lt;input&gt; &lt;soap:body use="literal"/&gt; &lt;/input&gt; &lt;output&gt; &lt;soap:body use="literal"/&gt; &lt;/output&gt; &lt;fault name="InvalidDeviceAddressException"&gt; &lt;soap:fault name="InvalidDeviceAddressException" use="literal"/&gt; &lt;/fault&gt; &lt;fault name="InternalServiceException"&gt; &lt;soap:fault name="InternalServiceException" use="literal"/&gt; &lt;/fault&gt; &lt;/operation&gt; ... &lt;/binding&gt; </code></pre> <p>Some parts of xsd file</p> <pre><code>&lt;xs:schema xmlns:tns="http://poweb13/" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0" targetNamespace="http://poweb13/"&gt; &lt;xs:element name="FReadStatus" type="tns:FReadStatus"/&gt; &lt;xs:complexType name="FReadStatus"&gt; &lt;xs:sequence&gt; &lt;xs:element name="arg0" type="xs:string" minOccurs="0"/&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; </code></pre> <p>i should have a SOAP response like this:</p> <pre><code>SOAP Response &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"&gt; &lt;S:Body&gt; &lt;ns2:FReadStatusResponse xmlns:ns2="http://poweb13/"&gt; &lt;return&gt;1&lt;/return&gt; &lt;/ns2:FReadStatusResponse&gt; &lt;/S:Body&gt; &lt;/S:Envelope&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload