unable to consume a web service on Android
I m trying to consuming Web service in android apps. Web Service that I create it in .net c#
I have this exception "unable to handle request without a valid action parameter. Please supply a valid soap.".
I don't know what should what is it the problem , and what should I to do.
please someone can help me !!
complet exception:
     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)
this my code, to consuming Web Service:
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;
     }
the code associed to Web Service application:
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;
        }
}
}
I found the problem. it work great!!
the only mistake it 's the value of namespace in java code, it should be
   String namespace="http://tempuri.org/";
instead,
   String namespace = "http://10.0.2.2:1378/";
上一篇: 在多线程中使用Web服务c#
下一篇: 无法在Android上使用Web服务
