-->

How to process the SOAPPRIMITIVE response

2019-09-03 14:58发布

问题:

I have WCF method that return String type.

This is my output

{"Table1" : [{"TableName" : "LoadDistributor","Description" : "Distributor ","MandatoryFlag" : "1","Status" : "","Priority" : "0"},{"TableName" : "LoadPrice","Description" : "Price ","MandatoryFlag" : "1","Status" : "","Priority" : "0"},{"TableName" : "LoadProduct","Description" : "Product ","MandatoryFlag" : "1","Status" : "","Priority" : "0"},{"TableName" : "LoadTradeSchemeDetail","Description" : "TradeSchemeDeta","MandatoryFlag" : "1","Status" : "","Priority" : "0"},{"TableName" : "RD.AlternativeProductDetail","Description" : "AltProdutDetail","MandatoryFlag" : "0","Status" : "","Priority" : "0"},{"TableName" : "RD.AlternativeProductHeader","Description" : "AltProdutHeader","MandatoryFlag" : "0","Status" : "","Priority" : "0"},{"TableName" : "RD.BatchPriceDetail","Description" : "BatchPrice ","MandatoryFlag" : "1","Status" : "","Priority" : "0"},{"TableName" : "RD.Executive","Description" : "Executive ","MandatoryFlag" : "1","Status" : "","Priority" : "0"},{"TableName" : "RD.Route","Description" : "Route ","MandatoryFlag" : "1","Status" : "","Priority" : "0"},{"TableName" : "RD.vwRetailer","Description" : "Retailer ","MandatoryFlag" : "1","Status" : "","Priority" : "0"},{"TableName" : "RD.vwRouteDetail","Description" : "RouteDetail ","MandatoryFlag" : "1","Status" : "","Priority" : "0"},{"TableName" : "XA.vwProductType","Description" : "Brand Product C","MandatoryFlag" : "1","Status" : "","Priority" : "0"},{"TableName" : "XA.vwTown","Description" : "Town ","MandatoryFlag" : "1","Status" : "","Priority" : "0"}]}

This is my Soap processing method

    // ksoap2 calling wcf
public SoapPrimitive soapPrimitive(String METHOD_NAME, String SOAP_ACTION, String NAMESPACE, String URL) throws IOException, XmlPullParserException {
    SoapPrimitive responses = null;
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); //set up request
    request.addProperty("strExec", "7067");
    request.addProperty("strBusinessUnit", "HEMA");
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); //put all required data into a soap envelope
    envelope.dotNet = true;
    envelope.setOutputSoapObject(request);  
    AndroidHttpTransport httpTransport = new AndroidHttpTransport(URL);  
    httpTransport.debug = true; 

    try{

        Log.w("Log_cat" ,"*********" + envelope.toString());
        httpTransport.call(SOAP_ACTION, envelope);
        Log.w("log_tag", " ===========" +SOAP_ACTION );

        // Object result = (Object)envelope.getResponse();
        // JSONArray jArray = new JSONArray(result.toString());
        // Log.w("log_tag", " ===*********==" +jArray );

         responses = (SoapPrimitive)envelope.getResponse();
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }

   // Object response= envelope.getResponse();
    return responses;
 }

My C# method return String with JSON( as a String).

How to get the Table name only in the List or Array. Please help me .What is wrong here?

回答1:

Do you understand the difference between SOAP and JSON? kSOAP is for processing services expecting SOAP request and returning SOAP response. So unless you have SOAP service returning single string element with JSON you don't need (and cannot use) kSoap. If you have REST service returning JSON use simple DefaultHttpClient and HttpPost as described for example here. If you are using JSON all the time it also answers your previous question.