【问题标题】:how to send xml file to android application using c#如何使用c#将xml文件发送到android应用程序
【发布时间】:2013-05-22 05:43:39
【问题描述】:

我想将数据从 c#(aspx) 发送到 android 应用程序。

我的 c#(aspx) 页面包含从 android 应用程序调用的代码,该代码从 sql 数据库中检索值并使用 DataSet 将其放入 XML 文件中,然后将 xml 文件返回给 android 应用程序。

从数据库中取出数据并存入xml的代码如下:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Xml;
using System.IO;

class ExecuteXmlReader
{
public static void Main()
{
String sConnection = "server=.\\SQLExpress;Integrated Security=SSPI;database=employee";
SqlConnection mySqlConnection = new SqlConnection(sConnection);
mySqlConnection.Open();

// Get the same data through the provider.
SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter("SELECT FirstName,LastName,Title,City from employees", sConnection);
DataSet myDataSet2 = new DataSet();myDataSet2.DataSetName = "Region";
mySqlDataAdapter.Fill(myDataSet2);


// Write data to files: data1.xml and data2.xml for comparison.

myDataSet2.WriteXml("c:/temp/employees.xml");
mySqlConnection.Close();
}

}

现在我如何将此 xml 文件返回到 android 应用程序。在 android 中,我使用 DOM XML parser 从文件中提取数据。

请帮助我。任何提示都将被接受。

【问题讨论】:

  • 您需要使用 dataset.getxml() 获取 xml 并编写函数以返回数据集。使用 httpclient 从 android 应用程序调用此方法,然后使用 DOM 解析器在 android 中解析 xml。希望这有帮助
  • 请您详细说明一下。以及我们如何从android调用特定的函数。?如果我们需要调用一个页面,那么我们可以使用final HttpClient client = new DefaultHttpClient(); StringBuffer temp = new StringBuffer("http://10.0.2.2:8347/LoginPage/Default.aspx"); 来调用它,但是如何调用一个可以返回一些值的函数。!
  • 构建webservice.then你需要有可以通过android代码调用的webmethod。
  • @SharadMhaske Web 服务已弃用。当我搜索它时...我发现现在使用 WCF。你知道如何创建一个这样的 WCF。任何提示或链接都会有所帮助。

标签: c# android dom xml-parsing


【解决方案1】:

使用它有示例 wcf webservice 并在 android-http://fszlin.dymetis.com/post/2010/05/10/Comsuming-WCF-Services-With-Android.aspx.hope 中使用这对你有帮助

【讨论】:

    猜你喜欢
    • 2011-11-13
    • 2017-11-03
    • 2015-07-24
    • 1970-01-01
    • 2014-12-17
    • 1970-01-01
    • 2017-10-31
    • 2019-10-22
    • 1970-01-01
    相关资源
    最近更新 更多