Monday, 30 July 2018

How to pass Array Parameters in Soap Request

Issue get due to could not pass correct String[] parameters in Soap Request as require in .Net Webservice

public void SoapKsop2_Api_Call(){

    SoapObject request = new SoapObject(namespace, methodName);    
    request.addProperty("Name", "Mr.Abc");

    String[] sqlPar =  new String[2];
    sqlPar[0] = "@FLAG";
    sqlPar[1] = "@RDeviNo";

    String[] sqlVal =  new String[2];
    sqlVal[0] = "RDevice";
    sqlVal[1]  = "123546";

    PropertyInfo PrfsqlParaName = getProperty(namespace,"sqlParaName",sqlPar);
    PropertyInfo sqlParaValue = getProperty(namespace,"sqlParaValue",sqlVal);

    request.addProperty(PrfsqlParaName);
    request.addProperty(sqlParaValue);

    int TimeOutInSeconds = 1000;

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = true;

    envelope.setOutputSoapObject(request);
    HttpTransportSE androidHttpTransport = new HttpTransportSE(url,TimeOutInSeconds * 1000);


    androidHttpTransport.call(soapAction, envelope);

    Log.d("test", "request: " + androidHttpTransport.requestDump);
    Log.d("test", "response: " + androidHttpTransport.responseDump);

    SoapObject result = (SoapObject)envelope.getResponse();
    String result  = result.getProperty(0).toString();

}

private PropertyInfo getProperty(String NAMESPACE,String name, String[] val) {

    PropertyInfo info = new PropertyInfo();
    info.name = name;
    info.namespace = NAMESPACE;

    //VECTOR_CLASS
    info.type = PropertyInfo.VECTOR_CLASS;


    Vector<String> vct = new Vector<String>();
    for (int i = 0; i < val.length; i++)
        vct.add(val[i]);
    info.setValue(vct);

    return info;
}

Error:

SoapFault - faultcode: 'soap:Server' faultstring: 'Server was unable to process request. ---> System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.NullReferenceException: Object reference not set to an instance of an object.
    at DmlCall.Save_Edit_Delete(String ProcName, String[] sqlParaName, String[] sqlParaValue) in Web Service line 36
    --- End of inner exception stack trace ---' faultactor: 'null' detail: org.kxml2.kdom.Node@16ba69a



from How to pass Array Parameters in Soap Request

No comments:

Post a Comment