Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to call a WCF service using ksoap2 on android?
    primarykey
    data
    text
    <p>Here is my code</p> <pre><code>import org.ksoap2.*; import org.ksoap2.serialization.*; import org.ksoap2.transport.*; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class ksop2test extends Activity { /** Called when the activity is first created. */ private static final String METHOD_NAME = "SayHello"; // private static final String METHOD_NAME = "HelloWorld"; private static final String NAMESPACE = "http://tempuri.org"; // private static final String NAMESPACE = "http://tempuri.org"; private static final String URL = "http://192.168.0.2:8080/HelloWCF/Service1.svc"; // private static final String URL = "http://192.168.0.2:8080/webservice1/Service1.asmx"; final String SOAP_ACTION = "http://tempuri.org/IService1/SayHello"; // final String SOAP_ACTION = "http://tempuri.org/HelloWorld"; TextView tv; StringBuilder sb; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); tv = new TextView(this); sb = new StringBuilder(); call(); tv.setText(sb.toString()); setContentView(tv); } public void call() { try { SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); request.addProperty("name", "Qing"); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( SoapEnvelope.VER11); envelope.dotNet = true; envelope.setOutputSoapObject(request); HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); androidHttpTransport.call(SOAP_ACTION, envelope); sb.append(envelope.toString() + "\n");//cannot get the xml request send SoapPrimitive result = (SoapPrimitive)envelope.getResponse(); //to get the data String resultData = result.toString(); // 0 is the first object of data sb.append(resultData + "\n"); } catch (Exception e) { sb.append("Error:\n" + e.getMessage() + "\n"); } } } </code></pre> <p>I can successfully access .asmx service, but when I try to call a wcf service the virtual machine said : Error: expected:END_TAG{<a href="http://schemas.xmlsoap.org/soap/envelope/" rel="noreferrer">http://schemas.xmlsoap.org/soap/envelope/</a>}Body(position:END_TAGhttp://schemas.xmlsoap.org/soap/envelope/}s:Fault>@1:712 in java.io.InputStreamReader@43ba6798</p> <p>How to print what the request send?</p> <p>Here is the wcf wsdl:</p> <pre class="lang-xml prettyprint-override"><code>&lt;wsdl:definitions name="Service1" targetNamespace="http://tempuri.org/"&gt; &lt;wsdl:types&gt; &lt;xsd:schema targetNamespace="http://tempuri.org/Imports"&gt; &lt;xsd:import schemaLocation="http://para-bj.para.local:8080/HelloWCF/Service1.svc?xsd=xsd0" namespace="http://tempuri.org/"/&gt; &lt;xsd:import schemaLocation="http://para-bj.para.local:8080/HelloWCF/Service1.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/"/&gt; &lt;/xsd:schema&gt; &lt;/wsdl:types&gt; &lt;wsdl:message name="IService1_SayHello_InputMessage"&gt; &lt;wsdl:part name="parameters" element="tns:SayHello"/&gt; &lt;/wsdl:message&gt; &lt;wsdl:message name="IService1_SayHello_OutputMessage"&gt; &lt;wsdl:part name="parameters" element="tns:SayHelloResponse"/&gt; &lt;/wsdl:message&gt; &lt;wsdl:portType name="IService1"&gt; &lt;wsdl:operation name="SayHello"&gt; &lt;wsdl:input wsaw:Action="http://tempuri.org/IService1/SayHello" message="tns:IService1_SayHello_InputMessage"/&gt; &lt;wsdl:output wsaw:Action="http://tempuri.org/IService1/SayHelloResponse" message="tns:IService1_SayHello_OutputMessage"/&gt; &lt;/wsdl:operation&gt; &lt;/wsdl:portType&gt; &lt;wsdl:binding name="BasicHttpBinding_IService1" type="tns:IService1"&gt; &lt;soap:binding transport="http://schemas.xmlsoap.org/soap/http"/&gt; &lt;wsdl:operation name="SayHello"&gt; &lt;soap:operation soapAction="http://tempuri.org/IService1/SayHello" style="document"/&gt; &lt;wsdl:input&gt; &lt;soap:body use="literal"/&gt; &lt;/wsdl:input&gt; &lt;wsdl:output&gt; &lt;soap:body use="literal"/&gt; &lt;/wsdl:output&gt; &lt;/wsdl:operation&gt; &lt;/wsdl:binding&gt; &lt;wsdl:service name="Service1"&gt; &lt;wsdl:port name="BasicHttpBinding_IService1" binding="tns:BasicHttpBinding_IService1"&gt; &lt;soap:address location="http://para-bj.para.local:8080/HelloWCF/Service1.svc"/&gt; &lt;/wsdl:port&gt; &lt;/wsdl:service&gt; &lt;/wsdl:definitions&gt; </code></pre> <p>It uses <code>&lt;xsd:schema&gt;</code> in tag <code>&lt;wsdl:types&gt;</code> and the asmx uses <code>&lt;s:schema&gt;</code> in tag <code>&lt;wsdl:types&gt;</code> what's the difference?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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