我试图弄清楚如何在 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>