Android Ksoap2 设置嵌套(子)类型的命名空间
我想将对象 SBINloggBegar
发送到 WCF Web 服务。 SBNInloggBegar
包含对象 SBPBegar
和 SBPInloggning
,它们又包含许多字符串。 SBPInloggning
还包含 SBPSubjekt
,其中包含许多字符串。 我已经使用 KvmSerialized
接口序列化了这些类。
我有一个如下所示的函数:
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 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 网站)。
I want to send an object, SBNInloggBegar
, to a WCF web service. SBNInloggBegar
contains the objects SBPBegar
and SBPInloggning
, which in turn contain a number of strings. SBPInloggning
also contain SBPSubjekt
, containing a number of strings.
I have serialized those classes using the KvmSerializable
interface.
I have a function that looks like this:
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;
}
This is what is sent:
<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>
I don't really want to set a namespace for <request>
. Instead I want the namespace in <request>
to be set for <BegarData>
and <InloggningsData>
. Also, I want <BegarData>
to set a namespace for it's children, and the same thing for <InloggningsData>
, like this:
...
<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>
...
Is there any way to do this?
By the way, I'm using version 2.5.4 (from the Google Code site).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我没有为
request
声明任何命名空间,但我添加了到特定类型的映射,如下所示:此外,我将
implicitTypes
设置为true
>。I didn't declare any namespace for
request
, but I added a mapping to the specific type, like this:Also, I set
implicitTypes
totrue
.