J'essayais de connecter l'application Android au service WCF, mais cela ne fonctionne pas. WCF est hébergé sur le serveur IIS. Je ne sais pas quel est l'application android incorrecte ou le service WCF lui-même. Le service WCF fonctionne correctement lorsqu'il est testé. Voici mon code de service WCF.Impossible de se connecter android au service WCF
[ServiceContract(Namespace = "http://services.example.com")]
public interface IEmployeeInfo
{
[OperationContract]
[WebInvoke(
BodyStyle = WebMessageBodyStyle.Wrapped,
Method="Get",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "GetEmployee/?key={employeeId}")]
Employee GetEmployee(int employeeId);
}
Voici mon code android dans lequel j'accède au service WCF
try {
DefaultHttpClient client = new DefaultHttpClient();
// http get request
HttpGet request = new HttpGet(EMPLOYEE_SERVICE_URI + evEmployeeId.getText());
Log.d("Connect","Connecting to Server 0");
Log.d("Connect","Connecting to Server 1");
// set the hedear to get the data in JSON formate
request.setHeader("Accept", "application/json");
request.setHeader("Content-type", "application/json");
//get the response
HttpResponse response = client.execute(request);
HttpEntity entity = response.getEntity();
//if entity contect lenght 0, means no employee exist in the system with these code
if(entity.getContentLength() != 0) {
// stream reader object
Reader employeeReader = new InputStreamReader(response.getEntity().getContent());
//create a buffer to fill if from reader
char[] buffer = new char[(int) response.getEntity().getContentLength()];
//fill the buffer by the help of reader
employeeReader.read(buffer);
//close the reader streams
employeeReader.close();
Log.d("Connect","Connecting to Server 2");
//for the employee json object
JSONObject employee = new JSONObject(new String(buffer));
//set the text of text view
tvEmployeeCode.setText("Code: " + employee.getString("EmployeeId"));
tvName.setText("Name: " + employee.getString("FirstName") + " " + employee.getString("LastName"));
tvAddress.setText("Address: " + employee.getString("Address"));
tvBloodGroup.setText("Blood Group: " + employee.getString("BloodGroup"));
}
else {
text.setTextSize(R.string.text);
}
}
catch (Exception e) {
Log.d("Error",e.getMessage());
e.printStackTrace();
}
Toute aide est appréciée.
Lorsque je demande le service WCF à partir de l'application de l'émulateur Android bloque. ici le logchat.
11-17 22:56:55.566: W/dalvikvm(1174): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
11-17 22:56:55.616: E/AndroidRuntime(1174): FATAL EXCEPTION: main
11-17 22:56:55.616: E/AndroidRuntime(1174): java.lang.NullPointerException: println needs a message
11-17 22:56:55.616: E/AndroidRuntime(1174): at android.util.Log.println_native(Native Method)
11-17 22:56:55.616: E/AndroidRuntime(1174): at android.util.Log.d(Log.java:138)
11-17 22:56:55.616: E/AndroidRuntime(1174): at com.yyousuf.sample.EmployeeInfoActivity.onClick
Alors, * qu'est-ce qui ne fonctionne pas? –
L'erreur semble être sur un appel à 'Log.d' êtes-vous sûr que c'est une exception dans cette méthode et si c'est vous êtes sûr que dans l'appel' Log.d ("Erreur", e.getMessage()); 'le message d'exception n'est pas nul? –
J'utilise le journal juste pour savoir où est l'erreur. En faisant cela. Je trouve quelque chose après // obtenir la réponse HttpResponse response = client.execute (request); n'est pas exécutée. Est-ce que mon URI est correcte. – user1435242