I have a C# solution which has a REST service project which uses another Class Library project. If I send a GET request, the service responds correctly. But, if I send a POST , the service's Post implementation works correctly inserting data in a database. However I receive no response status code ( 200 OK ) at the client end (Fiddler). Below you will find the code. Thanks in advance for your assistance.
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" };
}
}
}
The Post resource calls the following class:
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();
}
...
}
}
I found the bug in my code. I basically had a line at the end of the code Console.ReadLine();
which prevented the Post resource from finishing. Thanks to all of you !
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.