【问题标题】:Webservice to SQL server phonegap appWebservice 到 SQL Server phonegap 应用程序
【发布时间】:2013-08-01 11:27:56
【问题描述】:

我正在创建一个 Phonegap 应用程序,它需要连接到 SQL 数据库并将数据返回给应用程序。

我如何设置一个 WebMethod,它将:

  1. 创建与数据库的连接
  2. 查询数据库中的任何记录
  3. 将找到的记录返回到移动应用程序

我正在使用 Phonegap Build,所以我不能真正使用任何插件,并且 Web 服务和 SQL 数据库托管在我的计算机上,所以我将通过 192.168.xxx.xxx 连接到它们。

编辑: 到目前为止,我有一个从 Javascript 调用 Web 服务的方法:

index.js::

var url = "http://192.168.xxx.xxx:1234/"
$.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        url: url + "WebService.asmx/HelloWorld",
        data: "{}",
        success: function (data) {
        $("#ul_DeviceList").append('<li>Example ' + data.d + '</li>').listview('refresh');
        },
        error: function (data) {
        alert(data.status + " : " + data.statusText);
        }
});

WebService.cs::

[System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService
{
    [WebMethod]
    public string HelloWorld()
    {
        return "Hello World";
    }

这样我就可以知道设备是否已连接到服务器,它确实如此。

现在我认为需要按照以下方式做一些事情:

    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        [WebMethod]
        public void GetData()
        {
            SqlCeConnection conn = new SqlCeConnection(*Connection string will go here*);
            conn.Open();
           ..etc etc...

但目前我似乎无法将 System.data.SqlServerCe 添加到我的项目中..

【问题讨论】:

  • 向我们展示你到目前为止做了什么(一些代码),以及你停留在哪里

标签: sql cordova webmethod


【解决方案1】:

好吧,我无法用 C# 或任何语言帮助你。这超出了我的知识范围。

据我所知,如果您直接从浏览器本地打开它,您可以查询您的网络服务。如果你不能,那么你可以使用一个名为 SoapUI 的免费产品,女巫旨在查询网络服务

首先尝试处理服务器端:连接到您的数据库,编写测试方法以从数据库返回示例数据,然后才转到javascript。

顺便说一下,您的 HelloWorld 方法返回的不是 JSON 结构,因为您的 ajax 方法期望获取 JSON 格式的数据。

你在正确的道路上,只需要走得更远 :) 如果你需要一些帮助 - 只要问。祝你好运

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-26
    • 1970-01-01
    相关资源
    最近更新 更多