简体   繁体   English

NET中的Android中的ksoap

[英]ksoap in android with .net

am trying to connect to a web service in order to retrieve some data with an android device with ksoap2. 我试图连接到Web服务,以便使用带有ksoap2的android设备检索某些数据。 i assume that i have make the configuration correct and the result that i get back from the web service is anyType{} the code that i use is the below 我假设我已经使配置正确,并且从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)
    { }  

The SOAP file is SOAP文件是

SOAPAction: "http://tempuri.org/getPatient" 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>

i assume that the problem is in this line request.addProperty("patientID",8); 我认为问题出在这行request.addProperty(“ patientID”,8); but am not sure. 但不确定。 data on the server exist because am able to see them. 服务器上的数据存在,因为能够看到它们。 i would appreciate some help, an idea or a more detail tutorial 我希望获得一些帮助,想法或更详细的教程

Not sure, but I think your webservice is returning a complex object (Patient), but you are treating it as a string. 不确定,但是我认为您的Web服务返回的是复杂对象(患者),但是您将其视为字符串。 In that case, you need to have an Patient object that implements KvmSerializable Interface in order to receive the response. 在这种情况下,您需要具有一个实现KvmSerializable接口的Patient对象,以便接收响应。 Take a look at this: http://seesharpgears.blogspot.com/2010/10/ksoap-android-web-service-tutorial-with.html 看看这个: http : //seesharpgears.blogspot.com/2010/10/ksoap-android-web-service-tutorial-with.html

What is the method signature of getPatient? getPatient的方法签名是什么?

Correct code 正确的代码

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