【问题标题】:How to remove i:type="d:string" from PropertyInfo of SOAP in KSOAP2 Android如何从 KSOAP2 Android 中 SOAP 的 PropertyInfo 中删除 i:type="d:string"
【发布时间】:2013-04-18 09:24:32
【问题描述】:

我正在使用 ksoap2-android-assembly-3.0.0-jar-with-dependencies.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>

如何从 SOAP 请求中删除 i:type="d:string"

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

【问题讨论】:

  • 如果没有KSoap 库,您不能使用Soap 服务吗?有必要用吗?
  • @AndroidVogue..是的,因为我得到的 SOAP 响应解析起来非常复杂,所以我需要 ksoap..
  • 您可以使用 XML Parsers available 解析您的复杂响应 Like SAXParser XMLPullParser DOMParser 如果您在 XML 中收到响应,并且如果 JSON 响应仍然可以处理它安卓。我在没有 KSOAP 库的情况下处理了我的 SOAP 服务,它运行良好。

标签: android web-services soap ksoap2


【解决方案1】:

我在 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..

【讨论】:

  • 不需要编译所有库...只需要两个类,HttpTransportSE.java 和 Transport.java。而不是重新编译只需将这些复制到您的类包中。从您的包中导入类并像 amritpal 的答案一样进行编辑。 HttpTransportSE 扩展了 Transport。 HttpTransportSE httpTransport = new ttpTransportSE(url,timeOut);
【解决方案2】:

确保您已设置这些soap 信封属性:

    soapEnvelope.implicitTypes = true;
    soapEnvelope.dotNet = true;

并且在对象的getPropertyInfo 中返回字段的属性信息时,请确保您设置了正确的类型,例如:

    info.type = field.getClass();

【讨论】:

    【解决方案3】:

    你在哪里创作

    SoapSerializationEnvelope sEnvelop;
    

    只需分配sEnvelop.implicitTypes = true;

    不会创建"i:type="d:string"" or "i:type="d:long""内部数据类型标签,web服务可以成功执行

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多