c# – 将数据传递给.net Web服务并获取结果?
发布时间:2020-12-15 21:33:48 所属栏目:百科 来源:网络整理
导读:我需要一个有效的示例/教程,介绍如何将输入数据从 Android传递到.net Web服务以及将结果检索到Android应用程序. 请分享您可能认为与我的需求相关的指南,示例和教程的任何链接. 解决方法 您可以创建一个Rest Webservice,这里是一个 tutorial,您可以使用URI传
我需要一个有效的示例/教程,介绍如何将输入数据从
Android传递到.net Web服务以及将结果检索到Android应用程序.
请分享您可能认为与我的需求相关的指南,示例和教程的任何链接. 解决方法
您可以创建一个Rest Webservice,这里是一个
tutorial,您可以使用URI传递输入数据,您应该计划您的URI应该如何发布客户名称:
[OperationContract] [WebInvoke(Method = "POST",ResponseFormat = WebMessageFormat.Json,BodyStyle = WebMessageBodyStyle.Wrapped,UriTemplate = "json/post-customer/{name}")] void postCustomer(string name); 使用客户ID获取客户数据: [OperationContract] [WebInvoke(Method = "GET",UriTemplate = "json/get-customer/{id}")] Customer getCustomer(string id); 然后在托管您的web服务后,您需要使用HTTP客户端从您的Android应用程序访问它,例如: String uri = "uri to your service"; HttpClient httpclient = new DefaultHttpClient(); HttpGet request = new HttpGet(uri); ResponseHandler<String> handler = new BasicResponseHandler(); String result = null; try { result = httpclient.execute(request,handler); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } httpclient.getConnectionManager().shutdown(); 之后你应该在“result”中有一个字符串,这个字符串代表你的响应(json或xml). 希望这些信息可以帮到你. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |