5

引数の1つに配列が含まれていることを期待する.NETWebサービスにintの配列を送信しようとすると問題が発生します。これは、少なくとも私がWebサービスのAPIの説明から理解していることです。

<dataIndexIDs>
<int>int</int>
<int>int</int> </dataIndexIDs>

したがって、以下のように単一のintを送信しても、エラーは発生せず、正常に機能すると思います。

request.addProperty("dataIndexIDs", 63);

しかし、intの配列を送信しようとすると:

request.addProperty("dataIndexIDs", new int[] {63, 62}); // array of ints

または整数のArrayList:

ArrayList<Integer> indexes = new ArrayList<Integer>();
    indexes.add(63);
    indexes.add(62);
    request.addProperty("dataIndexIDs", indexes); // ArrayList of Integers

「java.lang.RuntimeException:シリアル化できません」という例外がスローされます。何か助けてください?私は何が間違っているのですか?ありがとう!

4

7 に答える 7

6

Androidクライアントから.NETサーバーに送信していますが、これでうまくいきました

SoapObject myArrayParameter = new SoapObject(NAMESPACE, MY_ARRAY_PARAM_NAME);
for( int i : myArray ) {
    PropertyInfo p = new PropertyInfo();
    p.setNamespace("http://schemas.microsoft.com/2003/10/Serialization/Arrays");
    // use whatever type the server is expecting here (eg. "int")
    p.setName("short");
    p.setValue(i);
    myArrayParameter.addProperty(p);
}
request.addSoapObject(myArrayParameter);

生産する

 <classificationIds>
     <n4:short i:type="d:long" xmlns:n4="http://schemas.microsoft.com/2003/10/Serialization/Arrays">18</n4:short>
 </classificationIds>

これはひどいように見えますが、サーバーはとにかくそれを食べます

于 2012-12-12T01:29:44.340 に答える
5

これがあなたを助けるかもしれない良い例です:

http://code.google.com/p/ksoap2-android/wiki/CodingTipsAndTricks

この問題に対する私の簡単な修正は次のとおりです。

SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(
            SoapEnvelope.VER11);

SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
soapEnvelope.setOutputSoapObject(Request);
soapEnvelope.dotNet = true;


List<Integer> companies =  new ArrayList<Integer>();
companies.add(65);
companies.add(66);
companies.add(67);

Request.addProperty("name", "test1");
SoapObject soapCompanies = new SoapObject(NAMESPACE, "companies");
for (Integer i : companies){
    soapCompanies.addProperty("int", i);
}
Request.addSoapObject(soapCompanies);

出力XML:

<n0:companies xmlns:n0 = "http://tempuri.org/">
            <int i:type = "d:int">65</int>
            <int i:type = "d:int">66</int>
            <int i:type = "d:int">67</int>
</n0:companies>
<name i:type = "d:string">test1</name>
于 2012-03-01T08:14:00.763 に答える
2

これは、KSOAP2 for Androidライブラリの既知の問題であり、現時点ではアレイをサポートしていません。問題の説明は次のとおりです。

http://code.google.com/p/ksoap2-android/issues/detail?id=19

サードパーティのパッチ、ソリューション、および例は、次の場所にあります。

http://people.unica.it/bart/ksoap2-patch/

WebサービスのWSDLも変更する必要があるため、個人的にはテストしていませんが、明らかに問題に対処しています。

于 2011-03-13T15:14:49.963 に答える
1

ミンダウガスに感謝します。あなたの答えへのわずかな編集は私のために働いた:

SoapObject soapObj = new SoapObject(namespace, "ImageId");
        for (Integer i : image_id){
            soapObj.addProperty("int", i);
        }
        request_login.addProperty("ImageId", soapObj);
于 2013-03-20T04:35:05.120 に答える
1

このようにパラメータ名と値をループに渡すだけです:

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE ht = new HttpTransportSE(URL);
for (int i=0; i<itemId.length; i++){
    request.addProperty("itemId",itemId[i]);
}
ht.call(SOAP_ACTION, envelope);

itemIdをパラメータ名としてループに渡し、値をループに渡すだけです。

于 2014-02-05T12:36:10.957 に答える
1

私の場合、これは配列要素を1つずつループで渡すことで機能します

public List<Integer> intsEnvio;
for(int i: intsEnvio){
    request.addProperty("clases", i);
}
于 2015-06-29T22:20:02.050 に答える
0

私にとってこれはうまくいく

SoapObject soapCompanies = new SoapObject(NAMESPACE, "listcardIDs");
            for (int i=0;i<passed.getListCardIds().size()-1;i++) {
                soapCompanies.addProperty("int", passed.getListCardIds().get(i));
            }
            soapObject.addSoapObject(soapCompanies);
            //soapObject.addPropertyIfValue("listCardIDs", soapCompanies);
            soapObject.addProperty("userID", passed.getuserId());
            soapObject.addProperty("gender", passed.isgender());
于 2019-04-27T10:48:28.893 に答える