2014-02-21 2 views
0

Я пытаюсь использовать веб-службу в приложениях для Android. Веб-сервис, который я создаю в .net C#не может использовать веб-службу на Android

У меня есть это исключение "невозможно обработать запрос без действительного параметра действия. Пожалуйста, поставьте действительное мыло.".

Я не знаю, что должно быть в чем проблема, и что мне делать.

, пожалуйста, кто-то может мне помочь !!

завершена исключение:

 Code: soap:Sender, Reason: System.Web.Services.Protocols.SoapException: unable to handle request without a valid action parameter. Please supply a valid soap. 
à System.Web.Services.Protocols.Soap12ServerProtocolHelper.RouteRequest() 
à System.Web.Services.Protocols.SoapServerProtocol.RouteRequest(SoapServerMessage message) 
à System.Web.Services.Protocols.SoapServerProtocol.Initialize() 
à System.Web.Services.Protocols.ServerProtocol.SetContext(Type type, HttpContext context, HttpRequest request, HttpResponse response) 
à System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean 
at org.ksoap2.serialization.SoapSerializationEnvelope.parseBody(SoapSerializationEnvelope.java:143) 
at org.ksoap2.SoapEnvelope.parse(SoapEnvelope.java:140) 
at org.ksoap2.transport.Transport.parseResponse(Transport.java:118) 
at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:272) 
at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:118) 

это мой код, чтобы потреблять веб-службы:

public class WebserviceCall { 

/** 
    * Variable Decleration................ 
    * 
    */ 
    String namespace = "http://10.0.2.2:1378/"; 
    private String url = "http://10.0.2.2:1378/Service1.asmx"; 

    String SOAP_ACTION; 
    SoapObject request = null, objMessages = null; 
    SoapSerializationEnvelope envelope; 
    HttpTransportSE androidHttpTransport; 

public WebserviceCall() { 
    // TODO Auto-generated constructor stub 
} 

/** 
    * Set Envelope 
    */ 
protected void SetEnvelope() { 

    try { 

     // Creating SOAP envelope   
     envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12); 

     //You can comment that line if your web service is not .NET one. 
     envelope.dotNet = true; 

     envelope.setOutputSoapObject(request); 
     androidHttpTransport = new HttpTransportSE(url); 
     androidHttpTransport.debug = true; 

    } catch (Exception e) { 
     System.out.println("Soap Exception---->>>" + e.toString());  
    } 
    } 

    //Authentification consuming WS 
    public client GetClientByAuthentification(String email,String password) 
    { 

     SOAP_ACTION = namespace + "GetClientByAuthentification"; 

     //Adding values to request object 
     request = new SoapObject(namespace, "GetClientByAuthentification"); 


     //Adding String value to request object 
     request.addProperty("eMail", "" + email); 
     request.addProperty("Password", "" + password); 

     SetEnvelope(); 



     //SOAP calling webservice 
      try { 
     androidHttpTransport.call(SOAP_ACTION, envelope); 


     //Got Webservice response 
     String result; 

     //result = envelope.getResponse().toString(); 

     SoapObject resp=(SoapObject) envelope.getResponse(); 
     result=resp.toString(); 
     Log.e("","result: "+result); 

     client clt= new client(); 
     clt.setClientFromXmlString(result); 
     if(!(clt.getNom().isEmpty())) 
        return clt; 
     else 
      return null; 

     } catch (SoapFault e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
     catch (HttpResponseException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } catch (IOException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } catch (XmlPullParserException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 

     return null; 
    } 

код associed приложению Web Service:

namespace WebService1 
{ 
/// <summary> 
/// Summary description for Service1 
/// </summary> 
[WebService(Namespace = "http://tempuri.org/")] 
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] 
[System.ComponentModel.ToolboxItem(false)] 

// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService] 
public class Service1 : System.Web.Services.WebService 
{ 
    string connectionString = "Data Source=TASSINEMOUHCINE;Initial Catalog=test;Integrated Security=True;Pooling=False"; 
    [WebMethod] 
    public string GetClientByAuthentification(string eMail, string Password) 
    { 
     SqlConnection connexion = new SqlConnection(connectionString); 

     SqlCommand command = new SqlCommand(); 
     //add Parameters 
     command.Parameters.Add("@eMail", SqlDbType.VarChar).Value = eMail; 
     command.Parameters.Add("@Password", SqlDbType.VarChar).Value = Password; 

     //Execution de la requête 2 permattant de calculer et stocker l'Age 
     command.Connection = connexion; 
     command.CommandType = CommandType.StoredProcedure; 
     command.CommandText = "GetClientByAuthentification"; 
     // 
     DataSet ds = new DataSet(); 
     SqlDataAdapter da = new SqlDataAdapter(command); 
     da.Fill(ds); 


     return contextTable(ds, 0, "client"); 
    } 

     private string contextTable(DataSet ds, int indiceTab, string balisePrincipalName) 
    { 
     string context = ""; 
     int i = 0; 
     foreach (DataRow row in ds.Tables[indiceTab].Rows) 
     { 
      context += "<" + balisePrincipalName + " id=\""+(i++)+"\">"; 
      foreach (DataColumn col in ds.Tables[indiceTab].Columns) 
      { 

       context += "<" + col.ColumnName + ">"; 
       context += row[col.ColumnName].ToString(); 
       context += "<" + col.ColumnName + "/>"; 

      } 
      context += "<" + balisePrincipalName + "/>"; 

     } 
      return context; 
     } 

} 
} 

ответ

0

Я нашел проблему. это хорошо работает !!

единственная ошибка это S значение имен в Java коде, он должен быть

String namespace="http://tempuri.org/"; 

вместо

String namespace = "http://10.0.2.2:1378/"; 

 Смежные вопросы

  • Нет связанных вопросов^_^