【发布时间】:2019-02-06 12:14:22
【问题描述】:
我是新来的,如果我不能很好地解释自己,我很抱歉。 我有一个基本的 asp.net RESTful API,它返回 2 个联系人,我从一个 Android 项目“使用它”,我的问题是我是否可以或如何将 web 服务连接到我在另一台机器上的 Microsoft SQL Server 2014 数据库。 我应该将 ContactRepository 中的连接作为一个简单的连接还是我需要做一些不同的事情? 我将代码留在下面:
ContactRepository:
namespace PruebaRestful.Services
{
public class ContactRepository
{
public Contact[] GetAllContacts()
{
return new Contact[]
{
new Contact
{
Id = 1,
Name = "Glenn Block"
},
new Contact
{
Id = 2,
Name = "Dan Roth"
}
};
}
}
}
联系人控制器:
namespace PruebaRestful.Controllers
{
public class ContactController : ApiController
{
private ContactRepository contactRepository;
public ContactController()
{
this.contactRepository = new ContactRepository();
}
public Contact[] Get()
{
return contactRepository.GetAllContacts();
}
}
}
谢谢大家,如果我需要写更多的东西,请在评论中告诉我。
【问题讨论】:
标签: c# sql-server rest web-services asp.net-mvc-4