2012-08-07 3 views
3

J'ai un problème avec l'appel WCF web service de Android application. Si j'appelle l'URL suivante, "http://10.0.2.2:80/WebService/WebServiceImpl.svc" j'obtiens la réponse "200 OK", mais quand j'essaye d'appeler la fonction au sein du service "http://10.0.2.2:80/WebService/WebServiceImpl.svc/Test" j'obtiens une réponse "400 Bad request".Appel Android service WCF

Quelqu'un peut-il aider?

namespace WebService 
{ 
    public class WebServiceImpl : IWebServiceImpl 
    { 
     #region IRestServiceImpl Members 
     public string Test() 
     { 
      return "Test pass"; 
     } 

     #endregion 
    } 
} 

namespace WebService 
{ 
    [ServiceContract] 
    public interface IWebServiceImpl 
    { 
    [OperationContract] 
     [WebInvoke(
      Method = "GET")] 
     string Test(); 
    } 
} 

Activité Android:

public void onClick(View v) 
    { 
     // TODO Auto-generated method stub 
     HttpClient client = new DefaultHttpClient(); 
     String SERVER_HOST="10.0.2.2"; 
     int SERVER_PORT = 80; 
     String URL = "http://10.0.2.2:80/WebService/WebServiceImpl.svc/Test"; 
     HttpHost target = new HttpHost(SERVER_HOST, SERVER_PORT, "http"); 
     HttpGet request = new HttpGet(URL); 
     try 
     { 
      HttpResponse response = client.execute(target,request); 
      HttpEntity entity = response.getEntity(); 
      MessageBox(response.getStatusLine().toString()); 
     } 
     catch(Exception e) 
     { 
      MessageBox("excepton"); 
      MessageBox(e.toString()); 
     } 
    } 

    public void MessageBox(String message){ 
     Toast.makeText(this,message,Toast.LENGTH_LONG).show(); 
    } 
+0

À quoi ressemble votre config sur le serveur? At-il le webHttpBinding avec le jeu de comportement correct? – Rajesh

Répondre

1

tester Tout d'abord cette URL dans le navigateur. Si vous avez le même problème, activez l'accès Web pour votre service dans le manifeste.

Vérification secondaire si ip 10.0.2.2 est utilisable sur votre téléphone.

2

je résous que l'utilisation de "SoapObject"

partie du code:

public static final String NAMESPACE = "http://tempuri.org/"; 
public static final String URL = "http://10.0.2.2:80/MyFirstPublishedWebService/WebServiceImpl.svc?wsdl"; 
public static final String SOAP_ACTION = "http://tempuri.org/IWebServiceImpl/Login"; 
public static final String METHOD_NAME = "Login"; 

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 
SoapSerializationEnvelope envelope = 
    new SoapSerializationEnvelope(SoapEnvelope.VER11); 

envelope .dotNet = true; 

envelope.setOutputSoapObject(request); 
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); 

try { 
    androidHttpTransport.call(SOAP_ACTION, envelope); 
} 
catch (Exception e) { 

} 

Alex, Merci pour la réponse!