如何从 KSOAP2 Android 中 SOAP 的 PropertyInfo 中删除 i:type="d:string"

2024-01-10

我正在使用 ksoap2-android- assembly-3.0.0-jar-with-dependency.jar

我正在开展一个项目,我需要以下肥皂请求:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:mod="http://www.tmforum.org/xml/tip/model" xmlns:cust="http://www.tmforum.org/xml/tip/customer/cust">
   <soapenv:Header/>
   <soapenv:Body>
      <mod:listProblemsRequest>
         <!--Optional:-->
         <mod:customer>

            <cust:iD >1100000677</cust:iD>
         </mod:customer>


      </mod:listProblemsRequest>
   </soapenv:Body>
</soapenv:Envelope>

但使用 KSOAP2 我能够生成以下请求:

<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>
      <retrieveCustomerProfileRequest xmlns="http://www.tmforum.org/xml/tip/model">
           <n0:customer xmlns:n0="http://www.tmforum.org/xml/tip/model">
               <n1:iD i:type="d:string" xmlns:n1="http://www.tmforum.org/xml/tip/customer      /cust">1100000990</n1:iD> 
   </n0:customer>
   </retrieveCustomerProfileRequest>
  </v:Body>
</v:Envelope>

我该如何删除i:type="d:string"来自 SOAP 请求。

请建议一个可以在 KSOAP2 源代码中完成的解决方案或任何解决方法,以便我能够生成适当的请求。


我在 ksoap 中找到了解决问题的方法:

1. Download the source code of Ksoap2.jar.
2.open up Transport .java and edit its :

    protected byte[] createRequestData(SoapEnvelope envelope, String encoding)
                throws IOException  

Method.

3.i edited it as follows:


protected byte[] createRequestData(SoapEnvelope envelope, String encoding)
            throws IOException {
        ByteArrayOutputStream bos = new ByteArrayOutputStream(bufferLength);
        byte result[] = null;
        bos.write(xmlVersionTag.getBytes());
        XmlSerializer xw = new KXmlSerializer();
        xw.setOutput(bos, encoding);
        envelope.write(xw);
        xw.flush();
        bos.write('\r');
        bos.write('\n');
        bos.flush();
        result = bos.toByteArray();
        xw = null;
        bos = null;


        String requestObject = new String(result);
        String pattern = "i:type=\"d:string\"";

        String resultString="";

        System.out.println("==earlier String==" + requestObject);
        if (requestObject.contains(pattern)) {

            System.out.println("==is it here ");
            resultString=requestObject.replace(pattern, "");

}

4.compile this class using classpath of ksoap2.jar
5.extract the ksoap2.jar and remove existing transport.class from it.
6.Add newly compiled .class file and make a new jar.
7.import the jar in your project.
Problem solved..
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何从 KSOAP2 Android 中 SOAP 的 PropertyInfo 中删除 i:type="d:string" 的相关文章

随机推荐