0
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

登录名和密码正确。

到目前为止我所做的:
Internet 权限
envelop.dotNet=true/false
SoapPrimitive response = (SoapPrimitive)envelope.bodyIn;

但这将给出同样的例外。请解决我的问题。

4

2 回答 2

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/

于 2012-10-25T21:35:12.257 回答
0

您必须检查您在 web 服务中接受的参数名称

soapObject.addProperty("登录名","ginnas"); soapObject.addProperty("密码","orcas");

参数名称必须与 web 服务中给出的名称匹配,例如。在网络服务中

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

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

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

如果您在 Web 服务中调用存储过程,那么

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

与前面的示例相同。只需检查参数名称。

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

于 2012-07-03T07:02:56.417 回答