1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
| public class TestActivity extends Activity
{
private static final String SOAP_ACTION = "http://tempuri.org/IService1/Request";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String METHOD_NAME = "Request";
private static final String URL = "http://extranet.synergy.fr/webservicema/Service1.svc?wsdl";
private EditText editText;
private Button button;
private String research="";
private static String soapResult = "";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.main);
editText = (EditText) findViewById(R.id.EditTextPrenom);
button = (Button) findViewById(R.id.ButtonEnvoyer);
button.setOnClickListener(
new OnClickListener() {
public void onClick(View v) {
research = editText.getText().toString();
String soapResult = soap("research", "marge");
//Affichage du résultat
soapResult = "Résultat du mot clé " + research + " : " + soapResult;
((TextView)findViewById(R.id.TextViewHello)).setText(soapResult);
}
}
);
}
public static String soap (String property, String value)
{
// Création de la requête SOAP
SoapObject request = new SoapObject (NAMESPACE, METHOD_NAME);
if (property != null)
{
request.addProperty(property, value);
soapResult = "Good Property : " + property + " - " + value;
}
else
{
return "Erreur Property";
}
//Toutes les données demandées sont mises dans une enveloppe.
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope (SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject (request);
HttpTransportSE androidHttpTransport = new HttpTransportSE (URL);
androidHttpTransport.debug = true;
//Envoi de la requête
androidHttpTransport.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
try {
androidHttpTransport.call (SOAP_ACTION, envelope);
} catch (IOException e1) {
return "IOException";
} catch (XmlPullParserException e1) {
return "XmlPullParserException";
}
try {
soapResult = soapResult + " et contenu de l'enveloppe = " + envelope.getResponse().toString();
} catch (SoapFault e) {
e.printStackTrace();
}
//soapResult = soapResult + " et contenu de l'enveloppe = " + envelope.bodyIn.toString();
return soapResult;
} |
Partager