0

我有带有网络线程的 Android / Java 项目。它连接到为我提供 GetAddonsTypes 方法的 WCF WebService。

GetAddonsTypes 返回 long、int 和 string 项,因此我使用自己的 Parser (String / regex),它还在 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();
    }
4

1 回答 1

1

也许这会有所帮助:

" 在 getProperty 方法中,我使用以下内容:

Info.type = MarshalBase64.BYTE_ARRAY_CLASS "

从这篇文章:http: //supportforums.blackberry.com/t5/Java-Development/Getting-Image-Over-Using-Web-Service-and-Ksoap2/td-p/491835

于 2013-04-17T11:17:12.170 回答