android KSoap故障异常传递参数

时间:2012-06-28 11:45:58

标签: android web-services

public class Result extends Activity {  

   private final String NAMESPACE = "http://tempuri.org/";
   private final String URL = "http://10.101.21.18/MDSService/Service1.svc?wsdl";
   private final String SOAP_ACTION = "http://tempuri.org/IService1/GetAssmtDataByLoginIdAndPassword";
   private final String METHOD_NAME = "GetAssmtDataByLoginIdAndPassword";

   public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
      SoapObject soapObject=new SoapObject(NAMESPACE, METHOD_NAME);
      Intent in = getIntent();
      soapObject.addProperty("loginName","ginnas");
      soapObject.addProperty("password","orcas");
     SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
     envelope.dotNet = true;
      envelope.setOutputSoapObject(soapObject);
      HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
      androidHttpTransport.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
   try {
       androidHttpTransport.call(SOAP_ACTION, envelope);
       System.out.println("call success");     
       SoapObject soapResponse = (SoapObject)envelope.getResponse();//throws the soap fault exception at this line
       Log.i("myApp", soapResponse.toString());

    } catch (org.xmlpull.v1.XmlPullParserException ex2) {
        System.out.println("EXCEPTION: " + ex2.getMessage());
    } catch (SoapFault e) {
        System.out.println("SOAPFAULT====");
        e.printStackTrace();
    } catch (IOException e) {
        System.out.println("IOEXCEPTION====");
        e.printStackTrace();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

此代码给出了以下异常:

SoapFault - faultcode: 'a:InternalServiceFault' faultstring: 'Query error occured : Procedure or function 'GetResidentAssmtDataByUser' expects parameter '@loginName', which was not supplied.' faultactor: 'null' detail: org.kxml2.kdom.Node@4053c030

登录名和密码正确无误。

到目前为止我做了什么:
互联网许可
envelop.dotNet =真/假
SoapPrimitive response =(SoapPrimitive)envelope.bodyIn;

但这会产生同样的例外。请解决我的问题。

2 个答案:

答案 0 :(得分:1)

 public String Convert()
            {
            String result = null;
            try
                {

                    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

                    request.addProperty("loginName","ginnas");
                    request.addProperty("password","orcas");

                    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
                    envelope.dotNet = true;

                    envelope.setOutputSoapObject(request);

                    HttpTransportSE httpTransport = new HttpTransportSE(URL);

                    Object response = null;

                    try
                        {
                            httpTransport.call(SOAP_ACTION, envelope);
                            response = envelope.getResponse();
                            result = response.toString();
                        }
                    catch (Exception exception)
                        {
                            response = exception;
                            result = response.toString();
                        }
                }
            catch (Exception e)
                {
                    System.out.println("Server responce" + e.getMessage());
                }
            return result;
        }

或看到此链接

http://www.c-sharpcorner.com/UploadFile/88b6e5/how-to-call-web-service-in-android-using-soap/

答案 1 :(得分:0)

您必须检查您在webservice

中传递的参数名称

soapObject.addProperty( “LOGINNAME”, “ginnas”);   soapObject.addProperty( “密码”, “逆戟”);

参数名称必须与webservice中指定的名称匹配 例如。在网络服务中

GetAssmtDataByLoginIdAndPassword(String @loginName,String @password)//Method in Webservice

然后你可以传递值为(在android中)

soapObject.addProperty("@loginName","ginnas");
  soapObject.addProperty("@password","orcas");

如果你在webservice中调用存储过程,那么

2)在webservice中,将参数传递给存储过程时,请检查参数名称

与上一个示例相同。只需检查参数名称。

如果您觉得困难或任何其他问题,那么您可以写信给我。