通过 Wp8 应用程序连接到 asp.net 网站中的数据库
Connecting to database in asp.net website by Wp8 app
我在 Visual Studio
的 asp.net 中创建了本地主机网站,并在那里添加了一个 MSSQL
连接。
我的问题是我为 windows phone 8
创建了一个应用程序,但我不知道如何将此应用程序与该网站上的数据库连接。
你能帮我解决这个问题吗?
首先:您的 Windows Phone 应用程序无法连接到 SQL 服务器数据库,因此您必须创建一个 API。
既然你用的是ASP.NET,我建议你看看Web API。简而言之:您将有几个 URL 端点,这些端点 return json/xml 到您的 Windows Phone 应用程序。查询数据库和 return URL 端点的控制器中的单个 item/list 项目是你的工作(如果你阅读创建 Web API).
下一个任务是连接到此 API。通常你会将它托管在 public url 上,这样你的 phone 设备就可以连接到它(phone 不知道你电脑的本地主机)。如果您想将 localhost 与模拟器一起用于测试,则必须执行下面引用中提到的任务,因为这不是开箱即用的。
When you create a WCF web service in Visual Studio, by default the
service is hosted in IIS Express and only accepts connections at
http://localhost/. Apps that target Windows Phone OS 7.1 can connect
to the development computer as localhost because the Windows Phone 7.1
emulator uses the network connection of the development computer. The
Windows Phone 8 Emulator, however, configures itself as a separate
device on the network. As a result, an app running on the Windows
Phone 8 Emulator can’t connect to the development computer as
localhost. Before you can connect successfully from the emulator to
the local web service, you have to make two changes:
- You have to configure the local web service and web server to accept connections from other devices on the network.
- You have to configure the service reference in the Windows Phone app to connect to the service by using the IP address of the development
computer on which the service is running.
来源:https://msdn.microsoft.com/en-us/library/windows/apps/jj684580(v=vs.105).aspx
我在 Visual Studio
的 asp.net 中创建了本地主机网站,并在那里添加了一个 MSSQL
连接。
我的问题是我为 windows phone 8
创建了一个应用程序,但我不知道如何将此应用程序与该网站上的数据库连接。
你能帮我解决这个问题吗?
首先:您的 Windows Phone 应用程序无法连接到 SQL 服务器数据库,因此您必须创建一个 API。
既然你用的是ASP.NET,我建议你看看Web API。简而言之:您将有几个 URL 端点,这些端点 return json/xml 到您的 Windows Phone 应用程序。查询数据库和 return URL 端点的控制器中的单个 item/list 项目是你的工作(如果你阅读创建 Web API).
下一个任务是连接到此 API。通常你会将它托管在 public url 上,这样你的 phone 设备就可以连接到它(phone 不知道你电脑的本地主机)。如果您想将 localhost 与模拟器一起用于测试,则必须执行下面引用中提到的任务,因为这不是开箱即用的。
When you create a WCF web service in Visual Studio, by default the service is hosted in IIS Express and only accepts connections at http://localhost/. Apps that target Windows Phone OS 7.1 can connect to the development computer as localhost because the Windows Phone 7.1 emulator uses the network connection of the development computer. The Windows Phone 8 Emulator, however, configures itself as a separate device on the network. As a result, an app running on the Windows Phone 8 Emulator can’t connect to the development computer as localhost. Before you can connect successfully from the emulator to the local web service, you have to make two changes:
- You have to configure the local web service and web server to accept connections from other devices on the network.
- You have to configure the service reference in the Windows Phone app to connect to the service by using the IP address of the development computer on which the service is running.
来源:https://msdn.microsoft.com/en-us/library/windows/apps/jj684580(v=vs.105).aspx