String uri = "http://192.168.24.117/ProductService.svc/GetArticleList"; DefaultHttpClient client=new DefaultHttpClient(); HttpPost requst=new HttpPost(uri); requst.setHeader("Accept", "application/json"); requst.addHeader("Content-Type", "application/json; charset=utf-8"); try { HttpResponse responsepost = client.execute(requst); if(responsepost.getStatusLine().getStatusCode()==200){ String response=EntityUtils.toString(responsepost.getEntity()); JSONObject jsonObject=new JSONObject(response); JSONArray arr = new JSONArray(jsonObject.getString("Data")); for(int i=0;i<arr.length();i++){ JSONObject item = (JSONObject) arr.get(i); Log.i(TAG,item.getString("Title")); } Log.i(TAG,jsonObject.getString("Data")); } } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); }
btnArticle.setOnClickListener(new OnClickListener(){ @Override public void onClick(View arg0) { String uri = "http://192.168.24.117/AppService.svc/GetArticleDetails"; DefaultHttpClient client=new DefaultHttpClient(); HttpPost requst=new HttpPost(uri); requst.setHeader("Accept", "application/json"); requst.addHeader("Content-Type", "application/json; charset=utf-8"); JSONObject jsonParams=new JSONObject(); try { jsonParams.put("sysNo","1"); HttpEntity bodyEntity=new StringEntity(jsonParams.toString(),"utf8"); requst.setEntity(bodyEntity); HttpResponse responsepost = client.execute(requst); if(responsepost.getStatusLine().getStatusCode()==200){ String response=EntityUtils.toString(responsepost.getEntity()); JSONObject jsonObject=new JSONObject(response); JSONObject jsonData=new JSONObject(jsonObject.getString("Data")); //Log.i(TAG,response); //Log.i(TAG,jsonObject.getString("Data")); Log.i(TAG,"编号:"+jsonData.getString("SysNo") +" 标题:"+jsonData.getString("Title")); } } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } });
<!--wcf begin--> <system.serviceModel> <bindings> <basicHttpBinding> <binding name="ServiceProxyBinding" sendTimeout="00:10:00" receiveTimeout="00:10:00" closeTimeout="00:10:00" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" > <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> </binding> <binding name="LargeSettings" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"> <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> <security mode="None" /> </binding> <binding maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"> <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> <security mode="None" /> </binding> </basicHttpBinding> <webHttpBinding> <binding maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" transferMode="Streamed"> <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> </binding> </webHttpBinding> </bindings> <!--services--> <services> <service name="Pisen.Service.Impl.ProductService" behaviorConfiguration="ProductServiceBehavior"> <endpoint address="" binding="webHttpBinding" contract="Pisen.Service.Contract.IProductService" behaviorConfiguration="web" /> </service> <service name="Pisen.Service.Impl.AppService" behaviorConfiguration="AppServiceBehavior"> <endpoint address="" binding="webHttpBinding" contract="Pisen.Service.Contract.IAppService" behaviorConfiguration="web" /> </service> </services> <!--behaviors--> <behaviors> <endpointBehaviors> <behavior name="web"> <webHttp helpEnabled="true" /> <dataContractSerializer maxItemsInObjectGraph="2147483647" /> </behavior> </endpointBehaviors> <serviceBehaviors> <behavior name="ProductServiceBehavior"> <dataContractSerializer maxItemsInObjectGraph="2147483647" /> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="true" /> </behavior> <behavior name="AppServiceBehavior"> <dataContractSerializer maxItemsInObjectGraph="2147483647" /> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="true" /> </behavior> <behavior name=""> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="false" /> </behavior> </serviceBehaviors> </behaviors> <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> </system.serviceModel> <!--wcf end-->
<uses-permission android:name="android.permission.INTERNET"></uses-permission>