我试图弄清楚如何抑制ksoap2库生成的xml输出中的i:type标记。我已经尝试了其他帖子中给出的答案,但他们没有奏效。有没有人有任何想法?
public static SoapObject createRequest() {
SoapObject method = new SoapObject(WS_NAMESPACE, WS_METHOD_NAME);
SoapObject request = new SoapObject("", "Request");
//Create source credentials object
SoapObject sourceCredentials = new SoapObject("", "SourceCredentials");
PropertyInfo sourceNameProp = new PropertyInfo();
//sourceNameProp.setNamespace(WS_NAMESPACE);
sourceNameProp.setName("SourceName");
sourceNameProp.setValue(SOURCENAME);
PropertyInfo passwordProp = new PropertyInfo();
//passwordProp.setNamespace(WS_NAMESPACE);
passwordProp.setName("Password");
passwordProp.setValue(PASSWORD);
sourceCredentials.addProperty(sourceNameProp);
sourceCredentials.addProperty(passwordProp);
SoapObject siteIds = new SoapObject("","SiteIDs");
PropertyInfo siteIDProp = new PropertyInfo();
//siteIDProp.setNamespace(WS_NAMESPACE);
siteIDProp.setName("int");
siteIDProp.setValue(SITE_IDS);
siteIds.addProperty(siteIDProp);
sourceCredentials.addSoapObject(siteIds);
request.addSoapObject(sourceCredentials);
PropertyInfo xMLDetailProp = new PropertyInfo();
//xMLDetailProp.setNamespace(WS_NAMESPACE);
xMLDetailProp.setName("XMLDetail");
xMLDetailProp.setValue("Full");
PropertyInfo pageSizeProp = new PropertyInfo();
//pageSizeProp.setNamespace(WS_NAMESPACE);
pageSizeProp.setName("PageSize");
pageSizeProp.setValue("10");
PropertyInfo curPageProp = new PropertyInfo();
//curPageProp.setNamespace(WS_NAMESPACE);
curPageProp.setName("CurrentPageIndex");
curPageProp.setValue("0");
request.addProperty(xMLDetailProp);
request.addProperty(pageSizeProp);
request.addProperty(curPageProp);
method.addSoapObject(request);
return method;
}
然后我们使用下面的代码段创建信封:
// 1. Create SOAP Envelope using the request
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.implicitTypes = true;
envelope.setAddAdornments(false);
envelope.setOutputSoapObject(parameter);
// 2. Create a HTTP Transport object to send the web service request
HttpTransportSE httpTransport = new HttpTransportSE(WSDL_URL);
httpTransport.debug = true; // allows capture of raw request/response in Logcat
// 3. Make the web service invocation
httpTransport.call(WS_NAMESPACE + "/" + WS_METHOD_NAME, envelope);
输出XML如下。问题是Web服务不喜欢Request和SourceCredentials节点上的i:type字段,我无法弄清楚如何抑制它们。有人可以帮忙吗?感谢。
<v:Envelope xmlns:i="http://www.w3.org/1999/XMLSchema-instance" xmlns:d="http://www.w3.org/1999/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/"><v:Header />
<v:Body>
<GetLocations xmlns="http://clients.mindbodyonline.com/api/0_5">
<Request i:type=":Request">
<SourceCredentials i:type=":SourceCredentials">
<SourceName i:type="d:string">PilatesonCollins</SourceName>
<Password i:type="d:string">XGn2PaLeRoD8qoDtrZfODu8j71c=</Password>
<SiteIDs i:type=":SiteIDs">
<int i:type="d:int">25755</int>
</SiteIDs>
</SourceCredentials>
<XMLDetail i:type="d:string">Full</XMLDetail>
<PageSize i:type="d:string">10</PageSize>
<CurrentPageIndex i:type="d:string">0</CurrentPageIndex>
</Request>
</GetLocations>
</v:Body>
</v:Envelope>
答案 0 :(得分:0)
您应为每个PropertyInfo
设置正确的类型:
propertyInfo.setType(value.getClass());
。
与envelope.implicitTypes = true;
相结合,它将起作用。