I already have my app for android. So far I've been using KSOAP communication with a web service - standard asmx file. Everything works just fine, but for a month I've been trying to use a self hosted WCF service to deliver data for my app.
I did already all combinations with configurations of WCF but still something is going wrong.
Please guys, I need sample project of something as simple as a HelloWorld WCF service for KSOAP.With configured endpoints,space etc. I will really appreciate.
I've spent a many hours searching the web, but I can't build a working service from the information I've found.
This is first time that I have to ask for help... Best Regards from Poland
I had same problem and solved in this way (WCF binding has to be basicHttpBinding, otherwise it doesn't work):
private static final String NAMESPACE = "http://tempuri.org/";
private static String URL="your url";
private static final String SOAP_ACTION_VALIDATION = "IValidateUser_wcf/ValidateUser";
private static final String VALIDATION_METHOD = "ValidateUser";
public boolean validateUser_WCF(String username, String password){
SoapSerializationEnvelope envelope = null;
SoapObject request = null;
HttpTransportSE httpTransportSE = null;
try {
request = new SoapObject(NAMESPACE, VALIDATION_METHOD);
request.addProperty("username", username);
request.addProperty("password", password);
envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
//////////////////////////////
// here you can add a HEADER element if you want
Element[] header = new Element[1];
header[0] = new Element().createElement(NAMESPACE_INFOCAD, "a1");
header[0].addChild(Node.TEXT, "HeaderTextContent");
envelope.headerOut = header;
//////////////////////////////
// second parameter is timeout:
httpTransportSE =
new HttpTransportSE(URL+VALIDATION_URI, 10*10000);
httpTransportSE.debug = true;
httpTransportSE.setXmlVersionTag(
"<?xml version=\"1.0\" encoding=\"utf-8\"?>");
httpTransportSE.call(NAMESPACE+SOAP_ACTION_VALIDATION, envelope);
// if response is a simple text result, you can call
// SoapPrimitive, if not, you have to call SoapObject
// result and navigate in response's tree like an xml file
SoapPrimitive result = (SoapPrimitive)envelope.getResponse();
//To get the data.
String textResult = result.toString();
Log.i("textResult", textResult);
return true;
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}finally{
// here you can see in LOG what is request you send and what is response received
Log.i(getClass().getSimpleName(),"requestDump : "+httpTransportSE.requestDump);
Log.i(getClass().getSimpleName(),"responseDump : "+httpTransportSE.responseDump);
}
return false;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.