连接的Windows Phone 8到SQL Server [英] Connecting Windows Phone 8 to Sql server

查看:134
本文介绍了连接的Windows Phone 8到SQL Server的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在的Windows Phone 8的开发没那么熟练,我想讨论/问什么是以我的Windows Phone 8连接到SQL服务器数据库的最佳方式即可。我试图通过互联网搜索,发现只有这并没有为我的的LINQ到SQL 使用的的WebService 工作几个导游。 是,我失败了。

As I'm not that skilled in Windows Phone 8 development I would like to discuss/ask what is the best way to connect my Windows Phone 8 to Sql-Server Database. I tried to search through the internet and found only few guides which didn't worked for me Linq-to-Sql using WebService. This is where I failed.

首先,我想显示的数据 - 这是最重要的,我不需要尚未对其进行编辑。但是,在未来这是必然的。

Firstly I would like to display data - this is most important, I don't need to edit them yet. But in future it is inevitable.

如果编辑会工作,我需要直接对其进行编辑SQL Server上到我连接。我还检查的SQL Server Compact 指南但只能在 CE 4.0的工作(当导出从SQL Server到SQL精简数据),其中不支持Windows Phone 8的。但是,即使它会工作是简单地复制SQL Server数据库SQL精简,不与SQL Server直接处理数据(这是可以理解的,因为它的SQL Server Compact)。

If the editing would work I need to edit them directly on Sql Server to which I'm connected. I also checked Sql Server Compact guide but that can only work under CE 4.0 (When exporting data from Sql Server to Sql Compact) which doesn't support Windows Phone 8. But even if it would work it simply copy the Sql server database to Sql Compact and doesn't work with data directly on Sql Server (which is understandable because it is Sql Server Compact).

所以当我被深深地搜索要做的是使用WebService的,只有这样,我跟一些一步一步上的 YouTube的但正如我前面提到的,问题是用的显示数据为先导,促使我使用列表框,因为它是Windows Phone的7.1和Windows Phone 8的只有LongListSelector。

So as I was searching deeply the only way to do that is using WebService I followed some step-by-step guides on YouTube but as I mentioned before, the problem was with displaying data as the guide led me to using ListBox because it was for Windows Phone 7.1 and in Windows Phone 8 is only LongListSelector.

我也发现了问题的连接的Windows Phone和Windows 8的应用程序到SQL Server 这是安静妄作。

I also found question Connect Windows Phone and Windows 8 apps to SQL Server which was quiet helpful for me.

我想我需要一些步进一步的指导如何做。所以,我想问问你,如果有任何一步一步的指导,如何连接WP8和SQL Server?如果有人是那种和这里编辑我的代码使它发挥作用。

I think I need some step-by-step guide how-to. So I would like to ask you if there is any step-by-step guide how to connect WP8 and Sql Server? If someone would be that kind and edit my code here to make it work.

感谢您的时间读这篇文章,答案/评论。

Thank you for your time reading this and answers/comments.

MS

推荐答案

好吧,实现自己的目标,我会做:

Well, to achieve your goal, I would do:


  1. 构建的ASP.NET Web API一个REST Web服务( http://www.asp.net/web -API ),它返回的对象(这些对象将被转换为自动JSON)。例如:

  1. Build a REST webservice with ASP.NET Web API (http://www.asp.net/web-api) which returns objects (those objects will be translated to json automatically). For example:

public class MyObject 
{
  public string Content { get; set; }
}

控制器是:

public class TestController : ApiController
{
  [HttpGet]
  public MyObject Example() {
    return new MyObject() { Content = "Hello World!" };
  }
}


  • 在您的赢手机使用HTTP客户端项目:

  • Use a HTTP client in your win phone project:

    HttpClient client = new HttpClient();
    client.BaseAddress = new Uri("http://mywebservice.com");
    client.DefaultRequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
    
    using (var result = await client.GetStreamAsync("test/example"))
    {
      var serializer = new JsonSerializer(); // this is json.net serializer
      using (var streamReader = new StreamReader(result)) {
        using (var jsonReader = new JsonTextReader(streamReader))
        {
          var obj = serializer.Deserialize<MyObject>(jsonReader);
          // you can access obj.Content now to get the content which was created by the webservice
          // in this example there will be "Hello World!"
        }
      }
    }
    


  • 当然,你可以创建更复杂的对象,这将是(德)序列化。只要看看在Web API教程。

    Sure you can create much more complex objects which will be (de)serialized. Just take a look at the Web API tutorials.

    在你的web服务,你现在可以访问任何你想要的数据库。

    Within your webservice you can now access any database you want.

    修改如果您需要更详细的答案,给我留下了评论。

    Edit If you need a more detailed answer, leave me a comment.

    这篇关于连接的Windows Phone 8到SQL Server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆