How to call a WCF service using soap2 on android?

Posted by Qing on Stack Overflow See other posts from Stack Overflow or by Qing
Published on 2010-04-07T01:39:10Z Indexed on 2010/04/07 1:43 UTC
Read the original article Hit count: 521

Filed under:
|
|

Hi all,

Here is my 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"); }

}

}

I can successfully access .asmx service, but when I try to call a wcf service the virtual machine said : Error: expected:END_TAG{http://schemas.xmlsoap.org/soap/envelope/}Body(position:END_TAG@1:712 in java.io.InputStreamReader@43ba6798

How to print what the request send?

Here is the wcf wsdl:

<wsdl:definitions name="Service1" targetNamespace="http://tempuri.org/">

- - - - - - - - - - - -

It uses in tag and the asmx uses in tag what's the difference? Thanks.

-Qing

© Stack Overflow or respective owner

Related posts about android

Related posts about ksoap2