簡體   English   中英

使用Azure SQL Server創建Web API

[英]Creating Web API Using Azure SQL Server

我使用以下代碼為xamarin應用嘗試了本教程

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
namespace XamarinLogin.Controllers
{
    public class ControllerNameController : ApiController
    {
        // GET: api/ControllerName
        public IEnumerable<string> Get()
        {
            return new string[] { "value1", "value2" };
        }

        // GET: api/ControllerName/5
        public string Get(int id)
        {
            return "value";
        }

        // POST: api/ControllerName
        public void Post([FromBody]string value)
        {
        }

        // PUT: api/ControllerName/5
        public void Put(int id, [FromBody]string value)
        {
        }

        // DELETE: api/ControllerName/5
        public void Delete(int id)
        {
        }
         xamarinloginEntities db = new xamarinloginEntities();  

        [HttpPost]  
        [ActionName("XAMARIN_REG")]  
        // POST: api/Login  
        public HttpResponseMessage Xamarin_reg(string username, string password)  
        {  
            Login login = new Login();  
            login.Username = username;  
            login.Password = password;  
            db.Logins.Add(login);  
            db.SaveChanges();  
            return Request.CreateResponse(HttpStatusCode.Accepted, "Successfully Created");  
        }  
        [HttpGet]  
        [ActionName("XAMARIN_Login")]  
        // GET: api/Login/5  
        public HttpResponseMessage Xamarin_login(string username, string password)  
        {  
            var user = db.Logins.Where(x => x.Username == username && x.Password == password).FirstOrDefault();  
            if (user == null)  
            {  
                return Request.CreateResponse(HttpStatusCode.Unauthorized, "Please Enter valid UserName and Password");  
            }  
            else  
            {  
                return Request.CreateResponse(HttpStatusCode.Accepted, "Success");  
            }  
        }  

    }
}

我已經完全按照教程學習了,但是仍然收到錯誤消息,這是錯誤消息,

The type or namespace name xamarinloginentities could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name Login could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name xamarinloginentities could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name Login could not be found (are you missing a using directive or an assembly reference?)

如您所見, Loginxamarinloginentities是我的ADO.NET實體數據模型,問題是如何獲得此錯誤消息。

找不到類型或名稱空間名稱xamarinloginentities (您是否缺少using指令或程序集引用?)

據我了解,類名(例如xamarinloginEntities )需要區分大小寫。 此外,如果按照提供的教程進行操作,則將在your Project Name -> ModelsControllerNameController.cs定義ASP.NET實體數據模型,您需要添加名稱空間引用,如下所示:

using XamarinLogin.Models;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM