c#REST服务帖子不会响应?

时间:2015-08-10 14:05:40

标签: c# rest

我有一个C#解决方案,它有一个REST服务项目,它使用另一个类库项目。如果我发送GET请求,服务会正确响应。但是,如果我发送 POST ,则服务的Post实现可以正确地在数据库中插入数据。但是,我在客户端(Fiddler)没有收到响应状态代码( 200 OK )。您将在下面找到代码。提前感谢你的帮助。

using System.Collections.Generic;
using System.Web.Http;


namespace OwinSelfhostSample
{
    public class ValuesController : ApiController
    {

        DatabaseConnector2.DatabaseLibrary database;

        // POST api/values 
        public void Post(Command command)
        {
            //create connection object and insert data
            database = new DatabaseConnector2.DatabaseLibrary(command.Instruction, command.Cell);
        }

        // GET api/values 
        public IEnumerable<string> Get()
        {
            return new string[] { "value1", "value2" };
        }
}
}

Post资源调用以下类:

using System;
using System.Data.SQLite;

namespace DatabaseConnector2
{
    public class DatabaseLibrary
    {

        // Holds our connection with the database
        SQLiteConnection m_dbConnection;
        Data_connection dbobject;

        // Only for testing
        //static void Main(string[] args)
        //{
        //    DatabaseLibrary p = new DatabaseLibrary("hola", "chao");
        //}

        public DatabaseLibrary(string instr, string cell)
        {
            //createNewDatabase();
            connectToDatabase(); 
            //createTable();                 
            insertDataInTable(instr, cell);
            printRecords();
        }
...
}
}

1 个答案:

答案 0 :(得分:0)

我在代码中发现了这个错误。我基本上在代码Console.ReadLine();的末尾有一行,这阻止了Post资源的完成。 谢谢你们所有人!

相关问题