将 WCF 服务与通用 Windows 应用程序捆绑在一起 [英] Bundle WCF service along with Universal Windows App

查看:30
本文介绍了将 WCF 服务与通用 Windows 应用程序捆绑在一起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我意识到我们无法从 UWP 应用程序直接访问 SQL Server 数据库,因此必须使用 WCF 服务作为中介.(这完全是愚蠢的,因为即使像 MySQL 这样的竞争对手也为 Microsoft 的运行时提供 API,而 Microsoft 自己的 RDBMS 没有!)

I realize that we cannot directly access SQL Server database from a UWP app, and have to use a WCF service as a mediator for this. (Which is totally stupid, since even competitors like MySQL provides API for Microsoft's runtime, while Microsoft's own RDBMS does not!)

我对 WCF 没有任何经验,但经过一些教程后,我相信我可以制作一个 WCF 服务来与我的 SQL Server 通信(虽然我不喜欢让我的简单应用程序使用 3 层架构,这不应该强加给我).无论如何,我不想在我的网站上托管这个 WCF 服务,因为我只是为这个 UWP 应用程序做这个.有没有办法可以将这个 WCF 服务与 UWP 应用程序本身捆绑/打包,这样服务仅在启动我的应用程序时在客户端计算机上运行,​​并在应用程序关闭/暂停/最小化时停止.

I don't have any experience with WCF, but after going through some tutorials, I believe I can make a WCF service to communicate with my SQL Server (although I do not like making my simple application use a 3-tier architecture, which shouldn't be imposed on me). Anyways, I do not want to host this WCF service on my website, since I'm making this only for this UWP app. Is there a way I can bundle/pack this WCF service along with UWP app itself, such that service runs on client machine only when thhe start my app, and stops later when app is closed/suspended/minized.

我正在开发的 UWP 应用程序,也有 WPF 版本和 Web 版本(在 ASP.NET 中),到目前为止,所有这些版本都连接到 MySQL 数据库,并且运行完美.最近我决定转向 SQL Server,因为我的所有软件都使用 Microsoft 技术,并且认为 SQL Server 将有更好的集成和支持.但现在我觉得相反,想切换回MySQL数据库.

The UWP app I'm developing, also have a WPF version and a web version (in ASP.NET), all of which were connected to MySQL database till now, and it worked flawless. Recently I decided to shift to SQL Server since I'm using Microsoft technologies for all my softwares and thought SQL Server will have better integration and support. But now I find it rather opposite, and thinking to switch back to MySQL database.

推荐答案

您不能将 WCF 服务(或 REST api)与您的通用 Windows 应用程序捆绑在一起.UWP 应用在与 WCF 服务不同的 .NET 运行时的沙盒环境中运行.您可以在 IIS 中运行 WCF 服务,甚至更好地创建一个自托管的 ASP.NET WebAPI 项目(因此不需要 IIS)来访问您的数据库.但此服务必须与应用单独安装.

You can not bundle a WCF service (or REST api) with your Universal Windows app. UWP apps run in a sandbox environment on a different .NET runtime than your WCF service. You could run the WCF service in IIS, or even better create a self-hosted ASP.NET WebAPI project (so no need for IIS) to access your database. But this service will have to be installed separately from the app.

请注意,由于 UWP 应用在沙箱中运行,因此一些应用内数据库(如 SQLite)在此沙箱中,默认情况下您的其他应用(WPF、网站)无法访问(有一些黑客可以绕过它).

Note that because UWP apps run in a sandbox, some in-app databases like SQLite are inside this sandbox and can not be accessed by your other apps (WPF, website) by default (there are some hacks to bypass this).

所以我认为最好的办法是坚持使用 MySQL 并使用 MySQL 连接器.

So I think your best bet is to stick with MySQL and use the MySQL connector.

这篇关于将 WCF 服务与通用 Windows 应用程序捆绑在一起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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