2012-01-11 120 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