如何在没有Restlet框架的Android上访问WCF数据服务?

时间:2012-02-24 12:39:38

标签: android wcf web-services restlet

我目前正在使用restlet fw来访问WCF数据服务。 我已从restlet支持站点复制代码,但它不起作用并给我错误 “无法获取http://xx.xx.xx/xxService.svc/ $元数据的元数据 - 通信错误[1001] ......!

我将不胜感激任何帮助。 提前致谢!

1 个答案:

答案 0 :(得分:0)

这是我做的对我有用的。在WCF服务界面中:

    [OperationContract,WebGet]    
    string Operation1();

WCF服务实现类

    string Operation1()
    {
     return "Some text";    
    }

在Java Android客户端

    URL url = new URL("http://xx.xx.xx/xxService.svc/Operation1");
    HttpURLConnection conn =(HttpURLConnection) url.openConnection();
    if (conn.getResponseCode() != 200) 
    throw new IOException(conn.getResponseMessage();
    }