我有带有网络线程的Android / Java项目。它连接到WCF WebService,后者为我提供方法GetAddonsTypes。
GetAddonsTypes返回long,int和string项目,因此我使用自己的Parser(字符串/正则表达式),该解析器还在myDataSource(它是SQLite数据库)中创建对象。现在,我的第二种方法GetProducts遇到了问题。 GetProducts返回long,int和Image。
我想将Image存储为byte []类型。但是,如何使用SoapObjects处理二进制文件?也许我应该将此anyType {}转换为二进制文件,但是我该怎么做呢?
这是GetProducts(.toString())的SoapObject结果的样子
anyType {DocumentElement = anyType {Tabela = anyType {ID = 701; lg = 1;
ProductImage = anyType {}; };
我的网络线程
Thread networkThread1 = new Thread() {
@Override
public void run() {
try {
final String METHOD_NAME = "GetAddonsTypes";
final String SOAP_ACTION = "http://tempuri.org/IService1/GetAddonsTypes";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
envelope.dotNet = true;
HttpTransportSE ht = new HttpTransportSE(URL);
ht.call(SOAP_ACTION, envelope);
final SoapObject result=(SoapObject)envelope.getResponse();
runOnUiThread (new Runnable(){
public void run() {
ParseTable(result.getProperty(1).toString());
}
});
}
catch (Exception e) {
Log.e("WS", e.toString());
}
}
};
public void ParseTable(String input)
{
myDataSource myDatasource;
Pattern p = Pattern.compile("(PID=)(\\d*); (flg=)(\\d*); (Name=)(\\w*);");
Matcher m = p.matcher(input);
myDatasource = new myDatasource(this);
myDatasource.open();
while (m.find()) {
try {
myDatasource.createMyItem(Long.parseLong(m.group(2)), Integer.parseInt(m.group(4)), m.group(6));
}
catch (Exception e) {
Log.e("Parser Error", e.toString());
}
}
myDatasource.close();
}
最佳答案
也许这会有所帮助:
“在getProperty方法中,我使用了以下方法:
信息类型= MarshalBase64.BYTE_ARRAY_CLASS
”
从这篇文章:http://supportforums.blackberry.com/t5/Java-Development/Getting-Image-Over-Using-Web-Service-and-Ksoap2/td-p/491835