我想將對象SBNInloggBegar
發送給WCF Web服務。 SBNInloggBegar
包含對象SBPBegar
和SBPInloggning
,它們又包含一些字符串。 SBPInloggning
也包含SBPSubjekt
,包含一些字符串。 我已經使用KvmSerializable
接口對這些類進行了序列化。Android Ksoap2設置嵌套(兒童)類型的名稱空間
我有一個功能,看起來像這樣:
private String soap() {
String returnString = "";
String NAMESPACE = "Sambruk";
String METHOD_NAME = "SBAInloggning";
String SOAP_ACTION = "Sambruk/AuthenticationService/SBAInloggning";
String URL = "http://exshaerpm.argentum.local/EliasTest/AuthenticationService/AuthenticationService.svc";
SoapObject soapRequest = new SoapObject(NAMESPACE, METHOD_NAME);
SBPBegar begar = new SBPBegar();
begar.setKommun("Skellefteå kommun");
SBPInloggning inloggning = new SBPInloggning();
inloggning.setAnvandarnamn("hej");
inloggning.setLosenord("hopp");
SBNInloggBegar inloggbegar = new SBNInloggBegar();
inloggbegar.setBegarData(begar);
inloggbegar.setInloggningsData(inloggning);
PropertyInfo prop = new PropertyInfo();
prop.setName("request");
prop.setNamespace("http://www.statskontoret.se/sambruk/nyttomeddelanden");
prop.setType(inloggbegar.getClass());
prop.setValue(inloggbegar);
soapRequest.addProperty(prop);
//soapRequest.addProperty("request", inloggbegar);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); //****
envelope.dotNet = true;
envelope.implicitTypes = true;
envelope.setAddAdornments(false);
envelope.setOutputSoapObject(soapRequest);
envelope.addMapping("http://www.statskontoret.se/sambruk/nyttomeddelanden", "", SBPBegar.class);
envelope.addMapping("http://www.statskontoret.se/sambruk/nyttomeddelanden", "", SBPInloggning.class);
envelope.addMapping("http://www.statskontoret.se/sambruk/sbpinloggning", "", SBPSubjekt.class);
HttpTransportSE aht = new HttpTransportSE(URL);
aht.debug = true;
try
{
aht.call(SOAP_ACTION, envelope);
//SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
Object o = envelope.getResponse();
SBNInloggSvar inloggSvar = new SBNInloggSvar((SoapObject) o);
returnString = inloggSvar.toString();
}
catch(Exception e)
{
e.printStackTrace();
returnString = e.toString();
}
return returnString;
}
這就是發送:
<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 />
<v:Body>
<SBAInloggning xmlns="Sambruk">
<n0:request
xmlns:n0="http://www.statskontoret.se/sambruk/nyttomeddelanden">
<BegarData>
<Kommun>Skellefteå kommun</Kommun>
<AppNamn i:null="true" />
<AppVersion i:null="true" />
<MaxAntalSvar i:null="true" />
<AnropsId i:null="true" />
<LastDataVersion i:null="true" />
</BegarData>
<Inloggningsdata>
<anvandarID i:null="true" />
<anvandarnamn>hej</anvandarnamn>
<organisationsAnvID i:null="true" />
<losenord>hopp</losenord>
<aktor i:null="true" />
<subjekt i:null="true" />
</Inloggningsdata>
</n0:request>
</SBAInloggning>
</v:Body>
</v:Envelope>
我真的不希望設置一個命名空間<request>
。相反,我希望<request>
中的名稱空間設置爲<BegarData>
和<InloggningsData>
。另外,我想<BegarData>
來設置它的孩子命名空間,同樣的事情<InloggningsData>
,像這樣:
...
<request xmlns:a="http://www.statskontoret.se/sambruk/nyttomeddelanden"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:BegarData xmlns:b="http://www.statskontoret.se/sambruk/sbpbegar">
<b:Kommun>test</b:Kommun>
...
</a:BegarData>
<a:InloggningsData xmlns:b="http://www.statskontoret.se/sambruk/sbpinloggning">
<b:AnvandarID></b:AnvandarID>
...
</a:InloggningsData>
</request>
...
有沒有辦法做到這一點?
順便說一下,我使用2.5.4版(來自Google Code站點)。
你試過這些嗎? [鏈接](http://seesharpgears.blogspot.com/2010/10/ksoap-android-web-service-tutorial-with.html) – PedroAGSantos 2011-05-13 11:47:54
我剛剛發現,當用方法實現KvmSerializable時,我可以設置命名空間字段。它接近我想要的解決方案,但它使每種類型都定義了它自己的名稱空間。我希望命名空間像一樣寫在標籤中,但是我希望孩子的命名空間可以在其父代的標籤中定義。 –
Shathur
2011-05-13 11:53:07
@subspider我已經試過這個鏈接,它並沒有幫助我,但是謝謝! – Shathur 2011-05-13 11:53:47