简体   繁体   English

在Android客户端中使用WCF数据服务

[英]Consume WCF Data Service in Android Client

I am a beginner in Android development. 我是Android开发的初学者。 I am trying to retrieve data through WCF data service. 我正在尝试通过WCF数据服务检索数据。 The service is configured to return data in both atom and json format. 该服务配置为返回atom和json格式的数据。

I am using odata4j library. 我正在使用odata4j库。 My code is below... 我的代码如下...

public class Welcome extends Activity {

Button call;
ListView list;
ArrayList categories;
ArrayAdapter adapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_welcome);

    setTitle("WCF Example");
    call = (Button) findViewById (R.id.mybtn);
    list = (ListView) findViewById(R.id.mylistview);
    categories = new ArrayList();
    call.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View arg0) {

            new callService().execute();
        }
    });
}
public class callService extends AsyncTask<Void, Void, ArrayList<String>> {
    @Override
    protected ArrayList<String> doInBackground(Void... params) {

    ODataConsumer c =                    ODataJerseyConsumer.create("http://217.37.219.177:82/EbosDataService.svc");
        List<OEntity> listEntities = c.getEntities("driver_details").execute().toList();
        System.out.println("Size"+ listEntities.size());
        if (listEntities.size() > 0) {
            for (OEntity entity : listEntities) {
                categories.add(entity.getProperty("DriverID").getValue().toString()
                        + " - "
                        + entity.getProperty("DriverFirstName").getValue());
            }
        }
        return categories;
    }
    @Override
    protected void onPostExecute(ArrayList<String> result) {            
        super.onPostExecute(result);
        adapter = new ArrayAdapter<String>(Welcome.this,
                android.R.layout.simple_list_item_1, result);
        list.setAdapter(adapter);
    }
}
}

When I run, the application become unresponsive. 当我运行时,应用程序变得无响应。 Please see the log 请查看日志

http://217.37.219.177:85/errorlog.txt

However when I access http://services.odata.org/Northwind/Northwind.svc my code works. 但是,当我访问http://services.odata.org/Northwind/Northwind.svc时,我的代码有效。 Please see the log 请查看日志

http://217.37.219.177:85/successlog.txt

I guess there is something wrong with my service. 我想我的服务有问题。 I cannot work out the issue as I am using the same service in different dot net client and it works fine. 我无法解决该问题,因为我在不同的点网客户端中使用了相同的服务,因此效果很好。

Any help will be much appreciated. 任何帮助都感激不尽。

Thanks. 谢谢。

I would suggest you debugging the app to solve NullPointerException. 我建议您调试应用程序以解决NullPointerException。

by the way, you are using OData earlier version. 顺便说一句,您正在使用OData的早期版本。 if you use OData V4 on server side, then on the client side, you can use Apache Olingo OData for Java Client @ http://olingo.apache.org/doc/odata4/download.html Olingo OData Client for Android Download (md5, sha512, pgp) 如果您在服务器端使用OData V4,则在客户端,可以使用Apache Olingo OData for Java Client @ http://olingo.apache.org/doc/odata4/download.html Olingo OData Client for Android下载(md5 ,sha512,pgp)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM