Android KSoap2是否可以使用Paramater Arrays将值传递给webservice方法? 如果是,怎么样?
对于VB:
Public Function calcSum(ByVal ParamArray args() As Double) As Double
对于C#
public static Double calcSum(params int[] args)
它是否可以正常传递这样的参数?
SoapObject request = new SoapObject(NAMESPACE + "/", methodCalcSumService);
request.addProperty("args", intArg1);
request.addProperty("args", intArg1); //2nd parameter, will this be overriden?
envelope.setOutputSoapObject(request);
androidHttpTransport.call(soapCalcSumService, envelope);
Object result = envelope.getResponse(); //Get XML Result
谢谢:)
答案 0 :(得分:0)
我需要将String []发送到VB Web服务方法
<WebMethod()> _
Public Function SendByteArrayString(ByVal ImageNo As String, ByVal Name As String, ByVal ParamArray ArrImage() As String) As Boolean
这段代码对我有用。希望这有帮助!
/** This class serialized String Array for passing PropertyInfo to Web Service
* Got this from hasanghaforian's answer (http://stackoverflow.com/questions/7130862/how-to-pass-string-array-to-webservice-using-ksoap2)
*/
public class SerializableStringArray extends Vector<String> implements KvmSerializable
{
private static final long serialVersionUID = -1166006770093411055L;
private int intPropertyCount = 1;
@Override
public Object getProperty(int arg0)
{
return this.get(arg0);
}
@Override
public int getPropertyCount()
{
return intPropertyCount;
}
@Override
public void getPropertyInfo(int arg0, Hashtable arg1, PropertyInfo arg2)
{
arg2.name = "string";
arg2.type = PropertyInfo.STRING_CLASS;
}
@Override
public void setProperty(int arg0, Object arg1)
{
this.add(arg1.toString());
}
@Override
public void setSize(int arg0)
{
intPropertyCount = arg0;
}
}
public final Boolean SendByteArrayString(String strServiceCallNo, String DBName, Bitmap[] bmp)
{
soapSendByteArrayString = NAMESPACE + "/" + methodSendByteArrayString;
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL, 60000);
boolean isValid = false;
try
{
isSuccessful = false;
SoapObject request = new SoapObject(NAMESPACE + "/", methodSendByteArrayString);
request.addProperty("ImageNo", strServiceCallNo);
request.addProperty("Name", strDBName);
SerializableStringArray serializedStringArray = new SerializableStringArray();
for (int i = 0; i < bmp.length; i++)
{
try
{
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp[i].compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
serializedStringArray.add(new String(Base64.encodeBase64(byteArray, false), "UTF-8"));
BusinessRules.appendLog("[ArrImage_" + i + " ]" + new String(Base64.encodeBase64(byteArray, false), "UTF-8"));
}
catch (Exception e)
{
e.toString();
}
}
serializedStringArray.setSize(bmp.length);
PropertyInfo propertyInfoStringArray = new PropertyInfo();
propertyInfoStringArray.setName("ArrImage");
propertyInfoStringArray.setValue(serializedStringArray);
propertyInfoStringArray.setType(String[].class); //Pass as a String[] class
request.addProperty(propertyInfoStringArray);
envelope.setOutputSoapObject(request);
Object result = "false";
try
{
envelope.addMapping(NAMESPACE, "ArrImage", new SerializableStringArray().getClass());
androidHttpTransport.call(soapSendByteArrayString, envelope);
result = envelope.getResponse(); //Get XML Result
}
catch (Exception e)
{
e.printStackTrace();
BusinessRules.appendLog("[WebService.java + SendByteArrayString + envelope.getResponse() ]" + e.toString());
}
isValid = Boolean.valueOf(result.toString());
}
catch (Exception e)
{
isValid = false;
e.printStackTrace();
BusinessRules.appendLog("[WebService.java + SendByteArrayString ]" + e.toString());
}
return isValid;
}