WCF et Application Android
Bonjour à tous,
Je désire faire une application Android toute bête utilisant un WebService WCF.
La méthode de mon WS que je veux utiliser est celle-ci:
Code:
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
| Public Function Request(ByRef research As String) As String Implements IService1.Request
Dim chaine As String = ""
Dim lstElement As DbDataReader
If String.IsNullOrEmpty(_connex.ConnectionString) Then
'_connex.ConnectionString = "Data Source=VMD-META-DEMO\SQLEXPRESS;Persist Security Info=True;User ID=*****;Password=*****;"
_connex.ConnectionString = "Data Source=VMD-SWIIP;Persist Security Info=True;User ID=****;Password=****;"
End If
If _connex.Type = clsConnectionBD.BDDType.NA Then
_connex.Type = clsConnectionBD.BDDType.SQLServer
End If
_connex.Open()
lstElement = _connex.ExecSelectToDR("SELECT NOM_INF, CMT_INF, RSP_INF, REG_INF FROM T_INF WHERE NOM_INF = '" + research + "' AND IDE_LANG = 1")
While lstElement.Read()
Dim nomItem As String = lstElement.Item("NOM_INF").ToString
Dim cmtItem As String = lstElement.Item("CMT_INF").ToString
Dim rspItem As String = lstElement.Item("RSP_INF").ToString
Dim regItem As String = lstElement.Item("REG_INF").ToString
chaine = nomItem + " ; " + cmtItem + " ; " + rspItem + " ; " + regItem
End While
Return chaine
End Function |
Actuellement, j'arrive à faire communiquer mon service et mon application UNIQUEMENT si j'utilise une fonction sans paramètre (par exemple qui renvoie une chaîne de caractères toute bête).
Lorsque je veux utiliser ma méthode avec mon argument de type String, j'ai cette erreur:
Citation:
AnyType{} blablabla
Voici mon code côté client Java:
Code:
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 78 79 80 81 82 83 84 85 86 87 88 89 90
| public class TestActivity extends Activity
{
private static final String SOAP_ACTION = "http://tempuri.org/IService1/Request";
private static final String METHOD_NAME = "Request";
//private static final String METHOD_NAME = "IService1_Request_InputMessage";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://******/webservicema/Service1.svc?wsdl";
//private static final String URL = "http://****/webservicema/WebService1.asmx";
private EditText editText;
private Button button;
private String research="";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.main);
//récupération de l'EditText grâce à son ID
editText = (EditText) findViewById(R.id.EditTextPrenom);
//récupération du bouton grâce à son ID
button = (Button) findViewById(R.id.ButtonEnvoyer);
//On applique un écouteur d'événement au clique sur le bouton
button.setOnClickListener(
new OnClickListener() {
public void onClick(View v) {
//on récupère le texte écrit dans l'EditText
research = editText.getText().toString();
//Appel de la fonction SOAP (Webservice)
String soapResult = soap("research", research);
//Affichage du résultat
soapResult = "Résultat du mot clé " + research + " : " + soapResult;
//Toast.makeText(this, "Bonjour " + research + " !", Toast.LENGTH_LONG).show();
((TextView)findViewById(R.id.TextViewHello)).setText(soapResult);
}
}
);
}
//public static SoapObject soap (String property, String value) throws IOException, XmlPullParserException
public static String soap (String property, String value)
{
// Création de la requête SOAP
SoapObject request = new SoapObject (NAMESPACE, METHOD_NAME);
//Ajout de propriété: addProperty(nom de variable, valeur) -> Le nom de la variable vient du fichier WSDL
if (property != null)
request.addProperty(property, value);
//Toutes les données demandées sont mises dans une enveloppe.
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope (SoapEnvelope.VER11);
//Préparation de la requête
envelope.bodyOut = request;
envelope.dotNet = true;
envelope.setOutputSoapObject (request);
HttpTransportSE androidHttpTransport = new HttpTransportSE (URL);
//Ceci est optionnel, on l'utilise pour savoir si nous voulons ou non utiliser
//un paquet "sniffer" pour vérifier le message original (androidHttpTransport.requestDump)
androidHttpTransport.debug = true;
//Envoi de la requête
try {
androidHttpTransport.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
androidHttpTransport.call (SOAP_ACTION, envelope);
} catch (IOException e) {
// TODO Auto-generated catch block
//e.printStackTrace();
return "erreur IOException";
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
//e.printStackTrace();
return "erreur XmlPullParserException";
}
//Obtention du résultat
try {
String soapResult = envelope.getResponse().toString();
return soapResult;
//return androidHttpTransport.responseDump;
} catch (SoapFault e) {
// TODO Auto-generated catch block
//return e.toString();
return "erreur SoapFault";
}
//return "erreur";
}
} |
Je pense qu'il doit y avoir un soucis avec la méthode "AddProperty"..
Je suis totalement novice dans le dév Android.. pouvez-vous m'aider ? ;)
Merci d'avance.