无法在Android上使用Web服务

我尝试在android应用程序中使用Web服务。 在.net中创建它的Web服务c#

我有这个异常“无法处理请求没有一个有效的行动参数,请提供一个有效的肥皂。”。

我不知道这是什么问题,我该怎么做。

请有人可以帮助我!

完成例外:

     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)

这是我的代码,以消费Web服务:

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;
     }

与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;
        }

}
}

我发现了这个问题。 它工作很棒!

唯一的错误是它在java代码中的命名空间的价值,它应该是

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

代替,

   String namespace = "http://10.0.2.2:1378/";
链接地址: http://www.djcxy.com/p/74521.html

上一篇: unable to consume a web service on Android

下一篇: connecting to a webservice from android