【发布时间】:2015-01-16 22:03:12
【问题描述】:
我正在尝试从 Android 调用 SOAP .NET 网络服务,该服务需要包含这样的元素的请求(从 .NET 网络服务客户端生成):
<InputVariable>
<Id>MyVariable</Id>
<Value i:type="a:string" xmlns:a="http://www.w3.org/2001/XMLSchema">Hello</Value>
</InputVariable>
这里有一些奇怪的东西 kSOAP 似乎没有直接支持。第一,我无法在 kSOAP 中找到一种方法来生成也具有属性的属性。我找到了this answer,它能让我走得更远,但仍然不准确。这是我通过该解决方案得到的结果:
<InputVariable>
<Id>MyVariable</Id>
<Value i:type="http://www.w3.org/2001/XMLSchema:string">Hello</Value>
</InputVariable>
SoapObject inputVariable = new SoapObject("", "InputVariable");
inputVariable.addProperty("Id", "MyVariable");
AttributeInfo att = new AttributeInfo();
att.setName("type");
att.setNamespace("http://www.w3.org/2001/XMLSchema-instance");
// I need some way to set the value of this to a namespaced string
att.setValue("http://www.w3.org/2001/XMLSchema:string");
ValueSoapObject valueProperty = new ValueSoapObject("", "Value");
valueProperty.setText("Hello");
valueProperty.addAttribute(att);
inputVariable.addSoapObject(valueProperty);
在运行时,服务器因无法反序列化的错误而失败:
Value' contains data from a type that maps to the name '://www.w3.org/2001/XMLSchema:string'. The deserializer has no knowledge of any type that maps to this name.
如何使用 kSOAP for Android 生成这种类型的 SOAP 属性?
【问题讨论】: