【问题标题】:Soap Fault VersionMismatch KSOAP2 for AndroidAndroid 的肥皂故障版本不匹配 KSOAP2
【发布时间】:2011-01-01 20:17:30
【问题描述】:

我正在尝试访问托管在此处的 Web 服务

http://srilanka.lk:9080/services/CropServiceProxy?wsdl

在 SoapUI 中工作正常。我得到了正确的回应。

SoapUI 请求

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:v1="http://schemas.icta.lk/xsd/crop/handler/v1/">
   <soap:Header/>
   <soap:Body>
      <v1:getCropDataList>
         <v1:code>ABK</v1:code>
      </v1:getCropDataList>
   </soap:Body>
</soap:Envelope>

SoapUI 响应

<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
   <soapenv:Body>
      <ns1:getCropDataListResponse xmlns:ns1="http://schemas.icta.lk/xsd/crop/handler/v1/">
         <ns1:cropInfo>
            <ns1:name>Ambul Kesel</ns1:name>
            <ns1:price>35.0</ns1:price>
            <ns1:location>Dambulla</ns1:location>
         </ns1:cropInfo>
         <ns1:cropInfo>
            <ns1:name>Ambul Kesel</ns1:name>
            <ns1:price>40.0</ns1:price>
            <ns1:location>Dambulla</ns1:location>
         </ns1:cropInfo>
      </ns1:getCropDataListResponse>
   </soapenv:Body>
</soapenv:Envelope>

但在 Ksoap2 for android 中,soap 响应是一个错误。以下分别是 requestDump 和 responseDump。

requestDump

<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>
<n0:getCropDataList id="o0" c:root="1" xmlns:n0="http://schemas.icta.lk/xsd/crop/handler/v1/"> 
<code i:type="d:string">CNT</code>
</n0:getCropDataList>
</v:Body>
</v:Envelope>

responseDump

<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<wsa:Action>http://www.w3.org/2005/08/addressing/soap/fault</wsa:Action>
<wsa:RelatesTo>urn:uuid:3257ABC779195052D01293913466558</wsa:RelatesTo>
</soapenv:Header>
<soapenv:Body>
<soapenv:Fault>
<faultcode>VersionMismatch</faultcode>
<faultstring>Only SOAP 1.1 or SOAP 1.2 messages are supported in the system</faultstring>
<detail />
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>

这是我的代码。

public void btnOnClick(View v){
        String NAMESPACE = "http://schemas.icta.lk/xsd/crop/handler/v1/";
        String URL = "http://220.247.225.202:9080/services/CropServiceProxy.CropServiceProxyHttpSoap12Endpoint";

        String METHOD_NAME = "getCropDataList";
        String SOAP_ACTION = "http://schemas.icta.lk/xsd/crop/handler/v1/getCropDataList";

        SoapObject soap_request = new SoapObject(NAMESPACE, METHOD_NAME);
        soap_request.addProperty("code", "ABK" );

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
        envelope.setOutputSoapObject(soap_request);
        envelope.addMapping(NAMESPACE, "cropInfo", CropInfo.class);
        envelope.dotNet=false;

        Marshal floatMarshal = new MarshalFloat();
        floatMarshal.register(envelope);

        System.out.println("body out : " + envelope.bodyOut.toString());

        AndroidHttpTransport http_transport = new AndroidHttpTransport(URL);
        //HttpTransportSE http_transport  = new HttpTransportSE(URL);
        http_transport.debug = true;
        try {
            http_transport.call(SOAP_ACTION, envelope);         

            //because we should expect a vector, two kinds of prices are given
            Vector<CropInfo> result_array = (Vector<CropInfo>)envelope.getResponse();
            if(result_array != null){
                for (CropInfo current_crop: result_array){
                    System.out.println(current_crop.getName());
                    System.out.println(Float.toString(current_crop.getPrice()));
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
            answer.setText("error caught");
            System.out.print("REQUEST: ");
            System.out.println(http_transport.requestDump);
            System.out.print("RESPONSE: ");
            System.out.println(http_transport.responseDump);
        }



    }

我怎样才能在 Ksoap2 中得到正确的响应?

【问题讨论】:

  • 您是否尝试使用 1.1 版?
  • 只是我的 5 美分 - 在点击监听器中做所有事情是非常冒险的,因为它在主 UI 线程上运行。所以在整个代码运行之前,UI 会被阻塞一段时间。想象一下无线电覆盖范围不好(网络速度低)的情况 - 很容易出现 ANR(应用程序无响应)错误弹出窗口。为避免这种情况,点击监听器应该启动其他一些(非 UI)Thread,或者我更愿意使用AsyncTask
  • 1.1 给出以下错误。 soapenv:Serverorg.apache.axis2.databinding.ADBException: Unexpected subelement code
  • 感谢 Arhimed,我将把它实现为 AsyncTask。但首先我必须让这项服务做出响应。我不知道是什么导致了这个错误。

标签: android soap soapui ksoap2


【解决方案1】:

您应该使用 1.1 并查看错误消息。服务器端的axis2 中的代码子元素有问题。可能只是您必须将implicitTypes 设置为false。试试信封上的一些选项。

【讨论】:

    【解决方案2】:

    SOAP 标准有多个规范,目前您正尝试使用 SOAP 1.2 标准发送请求,如您在此处看到的那样

    SoapSerializationEnvelope 信封 = 新 SoapSerializationEnvelope(SoapEnvelope.VER12);

    要解决此问题,您应该将请求作为 SOAP 1.1 标准发送,如下所示:

    SoapSerializationEnvelope 信封 = 新 SoapSerializationEnvelope(SoapEnvelope.VER11);

    【讨论】:

      【解决方案3】:

      看起来您没有设置代码对象的命名空间。您需要确保将目标命名空间设置为 http://schemas.icta.lk/xsd/crop/handler/v1/ 或将 n0 命名空间添加到代码元素。

      <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>
          <n0:getCropDataList id="o0" c:root="1" xmlns:n0="http://schemas.icta.lk/xsd/crop/handler/v1/"> 
            <n0:code i:type="d:string">CNT</code>
          </n0:getCropDataList>
        </v:Body>
      </v:Envelope>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-10-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多