2012-01-11 8 views
0

ksoap2のアンドロイドデバイスでデータを取得するために、Webサービスに接続しようとしています。私は、設定が正しく作る持っていると私は戻って、Webサービスから取得する結果がanyTypeの{}である私が使用するコードはksoap withアンドロイド

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

申し訳ありません...ウル問題は何ですか? –

+0

私の問題は、results.ifを取得していない、私は間違ったpatientIDを書くか、私は間違ったID番号を書く場合私の結果は:anyType {message =患者IDは存在しません。コード= -1; }私はこの時点まで、私はgetPatient xmlに行き、正しい結果を見つけると思います。フィールドのpathientIDに正しい情報を追加すると、結果は次のようになります。anyType {message = anyType {};コード= 0; } – prokopis

+0

このエラーはwebSeviceによって返され、サーバー側で何らかのエラーが発生していることを意味します。また、どのパラメータがオプション(nullではない)であるかを一度確認してください。 –

答えて

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

あなたの間違いについても説明してください –

1

わかりませんが、私はあなたのWebサービスが複雑なオブジェクト(患者)を返すと思いますが、あなたはそれを文字列として扱います。その場合、応答を受け取るためにKvmSerializable Interfaceを実装するPatientオブジェクトが必要です。これを見てください:http://seesharpgears.blogspot.com/2010/10/ksoap-android-web-service-tutorial-with.html

getPatientのメソッドシグネチャは何ですか?