我已經派幾個簡單的物體與KSOAP 2之前,但現在我有發送包含整數數組對象...發送對象爲int的數組與kSOAP2
所以我看着這個其他SO後:Serialize an array of ints to send using kSOAP2 但我發現了同樣的問題作爲文章的作者 - 我得到一個錯誤回話說:
The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:recipientIds . The InnerException message was 'Error in line 1 position 650. Element ' http://tempuri.org/:recipientIds ' contains data from a type that maps to the name ' http://schemas.microsoft.com/2003/10/Serialization/Arrays:recipientIds '. The deserializer has no knowledge of any type that maps to this name.
我的類:
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設置它...
你使用的是什麼版本的ksaop2-android?您鏈接到的問題已被修復.. –
我正在使用2.6.4。 – user1368800
我90%確定我的問題是我的名字空間是我添加的int的名字空間...我知道,當我在iOS中進行此調用時,我使用常見的http://tempuri.org/參數,但http://schemas.microsoft.com/2003/10/Serialization/Arrays \應以某種方式與int的使用,但顯然我在這裏做的方式是錯誤的 – user1368800