2012-06-28 39 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/