2012-06-28 36 views
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(); 
    } 

此代码给了我以下异常:安卓KSOAP故障异常参数传递

SoapFault - faultcode: 'a:InternalServiceFault' faultstring: 'Query error occured : Procedure or function 'GetResidentAssmtDataByUser' expects parameter '@loginName', which was not supplied.' faultactor: 'null' detail: [email protected] 

登录名和密码是否正确。

我迄今所做的:
Internet权限
envelop.dotNet =真/假
SoapPrimitive响应=(SoapPrimitive)envelope.bodyIn;

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

+0

你确定要传递正确的标签与请求?而且,您对网络服务有什么反应?一个对象或一个原始值? – Swayam

回答

0

您必须检查你通过在web服务

soapObject.addProperty( “登录名”, “ginnas”)接受参数名; soapObject.addProperty(“password”,“orcas”);

参数名称必须与webservice中给出的名称匹配 例如。在Web服务

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

那么你可以传递的值(在机器人)

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

,如果你调用存储过程中的Web服务,然后

2)在Web服务,同时传递参数存储过程检查参数名称

与上例相同。只检查参数名称。

如果你看起来很难或任何其他问题,那么你可以写我。

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/