2

以前にkSOAP2を使用していくつかの単純なオブジェクトを送信しましたが、整数の配列を含むオブジェクトを送信する必要があります...

だから私はこの他のSO投稿を見ました:kSOAP2を使用して送信するintの配列をシリアル化します しかし私はその投稿の作者と同じ問題を抱えています-私は次のようなエラーを受け取ります:

フォーマッタは、メッセージを逆シリアル化しようとしたときに例外をスローしました。パラメータ http://tempuri.org/:recipientIdsを逆シリアル化しようとしたときにエラーが発生しました。InnerExceptionメッセージは「1行目の650のエラー」でした。要素「http://tempuri.org/:recipientIds」には、名前「http://schemas.microsoft.com/2003/10/ 」にマップされるタイプのデータが含まれています。 Serialization / Arrays:recipientIds '。デシリアライザーは、この名前にマップされるタイプを認識していません。

私のクラス:

public class AddMessageConnection {
    private static final String SOAP_ACTION = "http://tempuri.org/IKindergarden/AddMessageAboutKid";
    private static final String METHOD_NAME = "AddMessageAboutKid";
    private static final String NAMESPACE = "http://tempuri.org/";
    private static final String NESTED_NAMESPACE = "http://schemas.microsoft.com/2003/10/Serialization/Arrays";
    private String URL;
    public String msg;
    public String kidID;
    public ArrayList<String> listOfEmployees = new ArrayList<String>();

    void connection()
    {
        Singleton service = Singleton.getInstance();
        service.getURL();
        String firstURL = service.getURL();
        URL = firstURL + "Kindergarden.svc";

        //Get parentID, parentToken
        String parentIDSingleton = service.getParentID();
        String parentTokenSingleton = service.getParentToken();

        //Initialize soap request
        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

        //Add parameters
        request.addProperty("authorId", service.getParentID());
        request.addProperty("relatesToKidId", kidID);

        SoapObject recipients = new SoapObject(NESTED_NAMESPACE, "recipientIds");

        //Add the recipients
        List<Integer> recp = new ArrayList<Integer>();
        //Iterate through recipients and add them
        for(int i = 0; i < listOfEmployees.size(); i++)
        {
            int converted = Integer.parseInt(listOfEmployees.get(i));
            recp.add(converted);
        }

        for(Integer i:recp)
        {
            recipients.addProperty("int", i);   
        }

        request.addSoapObject(recipients);

        request.addProperty("sMessage", msg);

        //Declare the version of the SOAP request
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

        //Debugging
        envelope.avoidExceptionForUnknownProperty=true;

        envelope.dotNet=true;
        envelope.implicitTypes=true;
        envelope.setAddAdornments(false);

        //Prepare request
        envelope.setOutputSoapObject(request);

        //Needed to make the internet call
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

        //Allow for debugging - needed to output the request
        androidHttpTransport.debug = true;

        try 
        {
            //this is the actual part that will call the web service
            androidHttpTransport.call(SOAP_ACTION, envelope);

            System.out.println("Request: " + androidHttpTransport.requestDump.toString());
            System.out.println("Response: " + androidHttpTransport.responseDump.toString());

        } catch(org.xmlpull.v1.XmlPullParserException ex2)
        {               
            System.out.println(androidHttpTransport.requestDump.toString());

        }  catch (Exception e)
        {
            e.printStackTrace();
            System.out.println(androidHttpTransport.requestDump.toString());
        }
    }
}

だから私はエラーが名前空間にあるという仮定でこれを修正しようとしています...誰かが私が何を変更すべきかについて何か手がかりを持っていますか?

SoapUIによると、サービスは次のことを期待しています。

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:arr="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
   <soapenv:Header/>
   <soapenv:Body>
      <tem:AddMessageAboutKid>
         <!--Optional:-->
         <tem:authorId>?</tem:authorId>
         <!--Optional:-->
         <tem:relatesToKidId>?</tem:relatesToKidId>
         <!--Optional:-->
         <tem:recipientIds>
            <!--Zero or more repetitions:-->
            <arr:int>?</arr:int>
         </tem:recipientIds>
         <!--Optional:-->
         <tem:sMessage>?</tem:sMessage>
      </tem:AddMessageAboutKid>
   </soapenv:Body>
</soapenv:Envelope>

iOSでリクエストを実行しました。xmlは次のようになります。

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:day="http://schemas.datacontract.org/2004/07/DayCare.DB.DTO">
<s:Header>
    <parentId xmlns="ns">2104541932</parentId>
    <parentToken xmlns="ns">00430050004A00430046004C0052</parentToken>
    <authType xmlns="ns">Parent</authType>
    <id xmlns="ns">1</id>
</s:Header>
<s:Body>
<AddMessageAboutKid xmlns="http://tempuri.org/">
    <authorId>2104541932</authorId>
    <relatesToKidId>2104535510</relatesToKidId>
    <recipientIds xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
        <d4p1:int>2104535836</d4p1:int>
        <d4p1:int>2104535839</d4p1:int>
    </recipientIds>
    <sMessage>Test</sMessage>
</AddMessageAboutKid>
</s:Body>
</s:Envelope>

一方、kSOAP2からの私のxmlは次のようになります。

<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
<v:Header>
    <n0:parentId xmlns:n0="ns">2104536774</n0:parentId>
    <n1:parentToken xmlns:n1="ns">0003</n1:parentToken>
    <n2:authType xmlns:n2="ns">Parent</n2:authType>
    <n3:id xmlns:n3="ns">1</n3:id>
</v:Header>
<v:Body>
<AddMessageAboutKid xmlns="http://tempuri.org/">
    <authorId>2104536774</authorId>
    <relatesToKidId>2104535421</relatesToKidId>
    <recipientIds i:type="n4:recipientIds" xmlns:n4="http://tempuri.org/">
        <int>2104535482</int>
        <int>2104535485</int>
    </recipientIds>
    <sMessage>Test</sMessage>
</AddMessageAboutKid>
</v:Body>
</v:Envelope>

だから私の推測では、問題はrecipientIds名前空間にあると思います... iOSで設定したところ、現在Androidでしか持っていませんが、SoapObjectsで正しく設定する方法がわかりません...

4

1 に答える 1

0

このように受信者を追加してみてください

request.addProperty("Arrays", recipients);

あるいは

request.addProperty("http://schemas.microsoft.com/2003/10/Serialization/Arrays", recipients);
于 2012-05-31T20:42:42.320 に答える