2012-01-11 33 views
0

正試圖連接到一個Web服務,以檢索一些數據與Android設備與KSOAP2。我認爲我有使配置正確,並且我從Web服務後面的結果anyType的{},我使用的代碼是低於ksoap在Android與.net

private static final String NAMESPACE = "http://tempuri.org/" ; 
private static final String URL = "http://IP/CardiacPortalWS/VitalInfoWS.asmx"; 
private static final String HelloWorld_SOAP_ACTION = "http://tempuri.org/getPatient"; 
private static final String METHOD_NAME1 = "getPatient"; 

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME1); 

    request.addProperty("patientID",8); 

    SoapSerializationEnvelope envelope =new SoapSerializationEnvelope(SoapEnvelope.VER11); 
    envelope.dotNet = true; 
    envelope.setOutputSoapObject(request); 
    AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL); 
    androidHttpTransport.debug=true; 
    SoapObject receivedString=null; 
    try 
    { 
     androidHttpTransport.call(HelloWorld_SOAP_ACTION, envelope); 
     receivedString = (SoapObject)envelope.getResponse(); 
     Log.v("Server", "server data1 "+receivedString.getPropertyCount()); 
     Log.i("Server", "server data2 "+receivedString.getProperty(0)); 
    } 
    catch(Exception e) 
    { } 

的SOAP文件是

的SOAPAction : 「http://tempuri.org/getPatient」

<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap:Body> 
    <getPatient xmlns="http://tempuri.org/"> 
     <patientID>int</patientID> 
     <name>string</name> 
     <SID>string</SID> 
     <sex>boolean</sex> 
     <birthday>dateTime</birthday> 
     <nationality>string</nationality> 
     <telephone>string</telephone> 
     <telephone1>string</telephone1> 
     <email>string</email> 
     <maritalStatusName>string</maritalStatusName> 
     <educationName>string</educationName> 
     <ejectionFraction>int</ejectionFraction> 
     <profession>string</profession> 
     <deathDateTime>dateTime</deathDateTime> 
     <deathReason>string</deathReason> 
     <isDead>boolean</isDead> 
    </getPatient> 
    </soap:Body> 
</soap:Envelope> 

<?xml version="1.0" encoding="utf-8"?> 
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap:Body> 
    <getPatientResponse xmlns="http://tempuri.org/"> 
     <getPatientResult> 
     <message>string</message> 
     <code>int</code> 
     </getPatientResult> 
     <name>string</name> 
     <SID>string</SID> 
     <sex>boolean</sex> 
     <birthday>dateTime</birthday> 
     <nationality>string</nationality> 
     <telephone>string</telephone> 
     <telephone1>string</telephone1> 
     <email>string</email> 
     <maritalStatusName>string</maritalStatusName> 
     <educationName>string</educationName> 
     <ejectionFraction>int</ejectionFraction> 
     <profession>string</profession> 
     <deathDateTime>dateTime</deathDateTime> 
     <deathReason>string</deathReason> 
     <isDead>boolean</isDead> 
    </getPatientResponse> 
    </soap:Body> 
</soap:Envelope> 

我假定,這個問題是在此行request.addProperty( 「patientID」,8);但我不確定。存在於服務器上的數據是因爲能夠看到它們。 我會感謝一些幫助,想法或更詳細的教程

+0

對不起......什麼是烏拉圭回合的問題? – 2012-01-12 06:37:48

+0

我的問題是,我沒有得到任何結果。如果我寫錯拼錯了patientID或我,如果我寫錯了身份證號碼我的結果是:anyType {message =病人ID不存在;代碼= -1; }我認爲直到這一點我繼續getPatient XML並找到正確的結果。當我在字段pathientID上添加正確的信息時,我得到的結果是:anyType {message = anyType {};代碼= 0; } – prokopis 2012-01-12 08:14:15

+0

這個錯誤是由webSevice返回的意思是在服務器端有一些錯誤。並檢查一次哪個參數是可選的(非空) – 2012-01-12 08:18:17

回答

0

正確的代碼

private static final String NAMESPACE = "http://tempuri.org/" ; 
private static final String URL = " http://IP/CardiacPortalWS/VitalInfoWS.asmx"; 
private static final String SOAP_ACTION = "http://tempuri.org/userLogin"; 
private static final String METHOD_NAME = "userLogin"; 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    try { 
     SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 
     request.addProperty("PatientID", "10"); 
     request.addProperty("Weight", "72"); 
     String currentDateTimeString = new SimpleDateFormat("yyyy-MM-dd"). 
      format(new Date()); 
     request.addProperty("DateTimeStamp",currentDateTimeString);//"2012-01-13"); 
     SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
      SoapEnvelope.VER11); 
     envelope.dotNet=true; 
     envelope.setOutputSoapObject(request); 
     HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); 
     androidHttpTransport.call(SOAP_ACTION, envelope); 
     Log.i("Server", "server data2 "+((Object)envelope.getResponse())); 
    } catch(Exception e) { 
     Log.e("Server", "Error on server "+e.getMessage()); 
    } 
} 
+0

你也應該解釋你的錯誤 – 2013-11-13 14:21:37