首页 > 解决方案 > 如何在 Soap 请求中传递数组参数

问题描述

由于无法按照 .Net Webservice 中的要求在请求中传递正确String[]的参数而导致的问题Soap

public void SoapKsop2_Api_Call(){

    SoapObject request = new SoapObject(namespace, methodName);    
    request.addProperty("ProcName", "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;
}

错误:

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


Soap Object

<Envelope xmlns="schemas.xmlsoap.org/soap/envelope/">; 
<Body>
 <Save_Edit_Delete xmlns="CnnRestro">
 <ProcName>[string?]</ProcName>
 <!-- Optional --> 
 <sqlParaName> <string>[string?]</string> </sqlParaName>
 <!-- Optional -->
 <sqlParaValue> <string>[string?]</string> </sqlParaValue> 
</Save_Edit_Delete>
 </Body> 
</Envelope> 

标签: android.netweb-servicessoapandroid-ksoap2

解决方案


推荐阅读