首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >通过C# MVC API执行查询

通过C# MVC API执行查询
EN

Stack Overflow用户
提问于 2017-07-31 22:11:41
回答 1查看 63关注 0票数 0

我在一些代码上遇到了问题,我似乎就是想不通。我正在尝试将一些数据发送到后端API,该API连接到我们的SQL Server并执行一个查询,而我并不希望得到任何类型的结果。我遇到的问题是SQL命令没有被发送到服务器,我得到了一个"404 -这个文件不存在“。

下面是请求的前半部分:

代码语言:javascript
运行
复制
public async Task ExportNewLists (string pid, string list)
    {
        var endpointUrl = string.Concat(baseEndpoint, "ExportLists", "/", pid, "/", list);
        AddAuthorization();
        using (HttpResponseMessage response = await client.GetAsync(endpointUrl))
        {
            if (!response.IsSuccessStatusCode)
            {
                Response.StatusCode = (int)response.StatusCode;
                var result = response.Content.ReadAsStringAsync().Result;
                var message = JsonConvert.DeserializeObject<ResponseError>(result);
            }
        }
    }

下面是我尝试调用的API函数:

代码语言:javascript
运行
复制
    [Route("api/Lists/ExportLists/{pid}/{list}")]
    [HttpGet]
    [ResponseType(typeof(void))]
    private async Task<IHttpActionResult> ExportList(string pid, string list)
    {
        using (var connection = db.Database.Connection)
        {
            try
            {
                connection.Open();
                var command = connection.CreateCommand();
                command.Connection = connection;
                command.CommandText = "EXEC LIST_EXPORT_SINGLE";
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.Add("@PID");
                command.Parameters["@PID"].Value = pid;
                command.Parameters.Add("@LIST");
                command.Parameters["@LIST"].Value = list;
                await command.ExecuteNonQueryAsync();
                connection.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        return Ok();
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-07-31 22:14:12

您已将ExportScrubList标记为私有。不能通过http调用标记为私有的操作。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45418257

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档