0
votes

I am a beginner in this, i am facing an issue while invoking asp.net web service method (SignUp) from android. It works fine when i try it from browser but when i do it from the android it gives me some exception like "

SoapFault - faultcode: 'soap:Client' faultstring: 'System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: SignUp. at System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest() at System.Web.Services.Protocols.SoapServerProtocol.Initialize() at System.Web.Services.Protocols.ServerProtocol.SetContext(Type type, HttpContext context, HttpRequest request, HttpResponse response) at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)' faultactor: 'null' detail: org.kxml2.kdom."

This is my Java Signup class

String SOAP_ACTION1 = "http://tempuri.org/SignUp";
String METHOD_NAME1 = "SignUp";
btn = (Button)findViewById(R.id.btn_signup);
    btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            new WebService().execute(METHOD_NAME1,SOAP_ACTION1,txt_name.getText().toString(),                  txt_email.getText().toString(),txt_password.getText().toString(),
                    txt_address.getText().toString(),
                    txt_dob.getText().toString(),
                    txt_account.getText().toString(),                       
                 txt_cnic.getText().toString(),txt_pobox.getText().toString(),                       
               txt_city.getText().toString(),txt_status.getText().toString());

This is My Java WebService Class

 private static String NAMESPACE = "http://tempuri.org/";
private static String URL = "http://192.168.0.102/MyWebService/WebService1.asmx?WSDL";
 protected String doInBackground(String... params) {
    String s="";
    String whichmethodcall = params[0];
    switch(whichmethodcall){
        case "SignUp":
            s = signup(params);
            break;
        case "SignIn":
            s = signin(params);
            break;
    }
    return s;
}
 public String signup(String[] arr){
    String s = "";
    SoapObject request = new SoapObject(NAMESPACE, arr[1]);
    //Use this to add parameters
    request.addProperty("cname",arr[2]);
    request.addProperty("cemail",arr[3]);
    request.addProperty("cpwd",arr[4]);
    request.addProperty("caddress",arr[5]);
    request.addProperty("cdob",arr[6]);
    request.addProperty("caccount",arr[7]);
    request.addProperty("cCnic",arr[8]);
    request.addProperty("cpobox",arr[9]);
    request.addProperty("cCity",arr[10]);
    request.addProperty("cstatus",arr[11]);

    //Declare the version of the SOAP request
    SoapSerializationEnvelope envelope = new 
    SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.setOutputSoapObject(request);
    envelope.dotNet = true;

    try {
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
        //this is the actual part that will call the webservice
        androidHttpTransport.call(arr[0], envelope);

        // Get the SoapResult from the envelope body.
       // SoapObject result = (SoapObject)envelope.bodyIn;
       // SoapObject result = (SoapObject) envelope.getResponse();
        if (envelope.bodyIn instanceof SoapFault) {
            final SoapFault result = (SoapFault) envelope.bodyIn;
            if (result != null) {
                //Get the first property and change the label text
                   s = result.toString();
            } else
                s = "No response";              
        }
    } catch (Exception e) {
        e.printStackTrace();
        s=e.getMessage().toString();
    }
    return s;
}

And This is My asp.net WebService method

 public string SignUp(string cname, string caddress, string cdob, long caccount, long cCnic, int cpobox, string cCity, string cstatus,string cemail, string cpass)
    {
        bool check = ConnectDB();           // Opens the Connection to Insert The new User
        string msg = "";
        //DateTime dob = DateTime.ParseExact(cdob, "dd/mm/yyyy", null);
        string query = "INSERT INTO Customers values('" + cname + "','" + caddress + "','" + cdob + "','" + caccount + "','" + cCnic + "','" + cpobox + "','" + cCity + "','" + cstatus + "','"+ cemail + "','"+ cpass + "')";
        SqlCommand comm = new SqlCommand(query, con);
        try{
            if (check == true){
                if (comm.ExecuteNonQuery() > 0)
                    msg = "you've signed up !";
                else
                    msg = "sign up error";                   
            }
            else               
                msg = "Database not Connected";               
        }catch (SqlException ex){
            msg = ex.Message.ToString();
            con.Close();
        }finally{
            con.Close();
        }
        return msg;
    }
1
Looks like you are using ksoap2. Transport has two fields requestDump and responseDump that very helpfull for debugging. Can you add something like this in finally clauseMaxim Tulupov
if (transport.requestDump != null) { Log.d(getClass().getName(), methodId + " " + transport.requestDump); } else { Log.d(getClass().getName(), "no request dump for " + methodId); } if (transport.responseDump != null) { Log.d(getClass().getName(), methodId + " " + transport.responseDump); } else { Log.d(getClass().getName(), "no response dump for " + methodId); }Maxim Tulupov

1 Answers

0
votes

Can you try this

instead of SoapObject request = new SoapObject(NAMESPACE, arr[1]); use

SoapObject request = new SoapObject(NAMESPACE, arr[0]);

In the soap object you should pass just method name, without http://...