开发者

Soap Fault VersionMismatch KSOAP2 for Android

开发者 https://www.devze.com 2023-02-02 15:01 出处:网络
I\'m trying to access a Web Service which is hosted here http://srilanka.lk:9080/services/CropServiceProxy?wsdl

I'm trying to access a Web Service which is hosted here

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

Works in SoapUI ok. I get the proper response in it.

SoapUI Request

<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 Response

<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>

But in Ksoap2 for android the soap response is an error. Following are the requestDump and responseDump respectively.

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>

Here is my code.

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)开发者_如何学Python;         

            //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);
        }



    }

How can I get a proper response in Ksoap2 for this?


You should be using 1.1 and check out the error message. Something in axis2 on the server side is having a problem with the code subelement. Might just be that you have to set implicitTypes to false. Try some of the options on the envelope.


There is more than one specification for the SOAP standard, currently you're trying to send a request using SOAP 1.2 standard as you can see here

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);

To fix, you should send your request as a SOAP 1.1 standard like this:

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);


Looks like you are not setting the namespace of the code object. You need to make sure you either set the target namespace to http://schemas.icta.lk/xsd/crop/handler/v1/ or add n0 namespace to the code element.

<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>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号