我正在使用Restlet-Framework 2.1.2,在我的Android应用程序中,我尝试从WCF数据服务检索数据并收到LogCat错误消息:
Starting the HTTP client Get the metadata for http://Server.domain.local:82/northdata.svc/ at http:// Server.domain.local:82/northdata.svc/$metadata GC_CONCURRENT freed 1154K, 56% free 2966K/6727K, external 1625K/2137K, paused 4ms+6ms Can't get the metadata for http://Server.domain.local:82/northdata.svc/ java.io.IOException: Unable to create customized SAX source ...
我的步骤: 我在Manifest文件中允许INTERNET权限:
uses-permission android:name="android.permission.INTERNET"
uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"
我替换HTTP客户端:
Engine.getInstance().getRegisteredClients().clear();
Engine.getInstance().getRegisteredClients().add(new HttpClientHelper(null));
并使用StrictMode:
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
我使用AsyncTask,我的代码:
protected String doInBackground(Object... params) {
{
try {
NorthdataService service = new NorthdataService();
Query<Customers> queryCustomers = service
.createCustomersQuery("/Customers");
}
} catch (Exception e) {
// return e;
}
return customers;
}
它可能是什么?我如何检查\从$ metadata中获取数据?
P.S。我在Android内部浏览器中打开了我的数据服务链接,它打开了。
答案 0 :(得分:1)
我解决了我的问题:
1.我创建新的Android项目
2.将Restlet-Framework中的文件复制到libs文件夹(在我的项目中):
org.restlet.jar
org.restlet.ext.atom.jar
org.restlet.ext.html.jar
org.restlet.ext.httpclient.jar
org.restlet.ext.net.jar
org.restlet.ext.odata.jar
org.restlet.ext.ssl.jar
org.restlet.ext.xml.jar
3.创建新包“northwindmodel”
4.从WCF DataService导入自动生成的java类
5.添加权限:
uses-permission android:name =“android.permission.INTERNET”
uses-permission android:name =“android.permission.WRITE_EXTERNAL_STORAGE”
uses-permission android:name =“android.permission.READ_EXTERNAL_STORAGE”
uses-permission android:name =“android.permission.ACCESS_NETWORK_STATE”
6.Incert code in onCreate:
NorthdataService service = new NorthdataService();
Query<Customers> query = service.createCustomersQuery("/Customers");
Log.d(log_tag, query.toString());
for (Customers cust : query){
Log.d(log_tag, "Customer Name - " + cust.getContactName());
}
在此之前我做了同样的事情,但问题在重新创建项目后得到了解决。