0

我正在使用 Web 服务在数据库中存储多个值。我已经创建了代码,但无法将值存储在远程数据库中。代码中没有错误,但值没有存储在数据库中。

这是我的代码:-

public String registerDoctor(String MethodName,Pojo p)
        {
            try 
            {
               SOAP_ACTION = namespace + MethodName;

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


               PropertyInfo registerDoctors =new PropertyInfo();

               //doctor name
               Log.v("name", p.getDoctorName().toString());
               registerDoctors.setName("doctorName");
               registerDoctors.setValue(p.getDoctorName());
               registerDoctors.setType(string.class);

             //doctor qualification
               Log.v("qualification", p.getQualification().toString());
               registerDoctors.setName("qualificaion");
               registerDoctors.setValue(p.getQualification());
               registerDoctors.setType(string.class);

             //doctor specialization
               Log.v("specialization", p.getSpecialization().toString());
               registerDoctors.setName("specialization");
               registerDoctors.setValue(p.getSpecialization());
               registerDoctors.setType(string.class);

             //doctor cityId
               Log.v("cityid", p.getCityId().toString());
               registerDoctors.setName("cityId");
               registerDoctors.setValue(p.getCityId());
               registerDoctors.setType(integer.class);

             //doctor areaId
               Log.v("areaid", p.getAreaId().toString());
               registerDoctors.setName("doctorName");
               registerDoctors.setValue(p.getAreaId());
               registerDoctors.setType(integer.class);


             //doctor phoneNo
               Log.v("phone", p.getPhoneNo().toString());
               registerDoctors.setName("phoneNo");
               registerDoctors.setValue(p.getPhoneNo());
               registerDoctors.setType(string.class);

             //doctor mobile1
               Log.v("mobile1", p.getMobile().toString());
               registerDoctors.setName("mobile1");
               registerDoctors.setValue(p.Mobile);
               registerDoctors.setType(string.class);

             //doctor mobile2
               Log.v("mobile2", p.getMobile2().toString());
               registerDoctors.setName("mobile2");
               registerDoctors.setValue(p.getMobile2());
               registerDoctors.setType(string.class);


               request.addProperty(registerDoctors);

               SetEnvelope();

                   try 
                   {

                            //SOAP calling webservice
                            androidHttpSE.call(SOAP_ACTION, envelope);

                            //Got Webservice response
                            String result = envelope.getResponse().toString();

                            Log.v("add log", result);
                            return result;

                        } 

                   catch (Exception e) 
                    {
                           // TODO: handle exception
                           return e.toString();
                    }

             }

            catch (Exception e) 
            {
                // TODO: handle exception
                return e.toString();
            }               
    }
4

2 回答 2

0

ArrayListPropertyInfo 发送到服务器。将 PropertyIfo更改server side为接收ArrayList。我希望它有所帮助。

于 2014-05-19T08:49:02.890 回答
0

正确检查 web 服务上的查询、soapaction、命名空间、方法名称和 url。然后使用下面的方法。它更简单更好

public static boolean regist(String Student_Name,String Last_Name,String Email_ID,String Mobile_Number,
                                 String Name_Of_The_College,String Qualification,String Location,String Fellowship,String Reference,
                                 String FeeStatus,String Slatitude,String Slongitude,String webMethName)
    {

        String registerresponse="flag";
        Email_ID="Blank";
        Location="Blank";


        String URL ="your url";
        String METHOD_NAMEREG = "your method name";
        String NamespaceR="your namespace", SOAPACTIONREG="your action";

        try{



            //long FellowshipL = Long.valueOf(Fellowship);

            SoapObject request = new SoapObject(NamespaceR, METHOD_NAMEREG);
//Note:"Candidate_Name" is property name mentioned in your webservice
//Student_Name is your value that to be inserted

            request.addProperty("Candidate_Name", Student_Name);
            request.addProperty("LastName", Last_Name);
            request.addProperty("email", Email_ID);
            request.addProperty("Mobile", Mobile_Number);
            request.addProperty("College_Name", Name_Of_The_College);
            request.addProperty("Qualification", Qualification);
            request.addProperty("Location", Location);
            request.addProperty("Fellowshipid", FellowshipL);
            request.addProperty("referenceName", Reference);
            request.addProperty("FeesStatus", FeeStatus);

            request.addProperty("lat",Slatitude);
            request.addProperty("lon",Slongitude);
//      request.addProperty("to", 9);

            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.dotNet = true;
            //Set output SOAP object
            envelope.setOutputSoapObject(request);
            //Create HTTP call object
            HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

            try
            {

                androidHttpTransport.call(SOAPACTIONREG, envelope);
                //  Log.i(TAG, "GetAllLoginDetails is running");
//        result1 = (Vector<SoapObject>) envelope.getResponse();
                SoapPrimitive  response = (SoapPrimitive ) envelope.getResponse();
                Log.i("string value at resp",response.toString());

                registerresponse=response.toString();

            }
            catch (Throwable t) {
                //Toast.makeText(MainActivity.this, "Request failed: " + t.toString(),
                //    Toast.LENGTH_LONG).show();
                Log.e("request fail", "> " + t.getMessage());
            }
        }catch (Throwable t) {
            Log.e("UnRegister Receiver Err", "> " + t.getMessage());

        }

        if(registerresponse.equals("Record Saved."))
        {return true;}
        else
        {return false;}
    }
于 2016-12-17T11:21:04.370 回答