簡體   English   中英

NET中的Android中的ksoap

[英]ksoap in android with .net

我試圖連接到Web服務,以便使用帶有ksoap2的android設備檢索某些數據。 我假設我已經使配置正確,並且從Web服務獲取的結果是anyType {}我使用的代碼如下

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); 但不確定。 服務器上的數據存在,因為能夠看到它們。 我希望獲得一些幫助,想法或更詳細的教程

不確定,但是我認為您的Web服務返回的是復雜對象(患者),但是您將其視為字符串。 在這種情況下,您需要具有一個實現KvmSerializable接口的Patient對象,以便接收響應。 看看這個: http : //seesharpgears.blogspot.com/2010/10/ksoap-android-web-service-tutorial-with.html

getPatient的方法簽名是什么?

正確的代碼

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());
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM