Saturday, October 6, 2012

[Andoird/.NET] Android and WCF template

I've been working a lot with setting up WCF locally. Now it is time to do the true test and connect my android with the sucka!

To set up the WCF, just follow this post:

Setting Up WCF in Virtual Directories

All you need is Android and Eclipse set up. Also, get the KSoap plug-in and add it to your library. Now just add this to your code:

 private static String SERVICE_URI = "";

 private static final String METHOD_NAME = "GetData";

 private static final String NAMESPACE = "";

 private static final String URL = "";

 private static final String SOAP_ACTION = "";

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);


 SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

 envelope.dotNet = true;
 HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);,envelope);
 SoapPrimitive result = (SoapPrimitive)envelope.getResponse();
 String resultData = result.toString();

EDIT: Btw, the request.addProperty method is a parameter of your method. And if you don't know your namespace, look at the wsdl of your service. This was done to target an Android 2.2 device. If you noticed, I was using the template VS2010 gives when you create a new Web Service.

Also, I tried using HttpResponse and HttpEntity, but I got no response when I tried to do something like I believe it has something to do with the binding. By default, WCF uses WSHttpBinding I think. I tried changing to BasicHttpBinding, but the configuration had issues finding MetaData. That is it for now.

No comments:

Post a Comment