没有输入时如何解决邮递员应用程序中POST的请求错误?

时间:2019-03-19 04:44:17

标签: rest wcf postman

我在我的应用程序中实现了WCF服务,该服务访问数据库以返回响应。这是RESTful服务。

下面的API是POST Api,它不输入​​任何内容,但会返回json响应。因此,我在邮递员中以这种方式发送数据,但是我总是收到此错误。无法了解问题所在。

Postman screenshot

[OperationContract]
[WebInvoke(UriTemplate = "/FetchPOLList", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
POLList FetchPOLList();

我在同一servicecontract中有另一个webinvoke,它运行正常。它具有在同一端口上运行的json输入和json输出。

有人可以告诉我这是什么问题吗?

1 个答案:

答案 0 :(得分:1)

在我看来,代码片段没有问题。我注意到您使用ORM框架从数据库中获取数据。您是否正确设置了数据库连接字符串?或数据库连接有问题。为了排除此因素,建议您首先返回固定数据。 这是我类似的通过Entity Framework从数据库获取数据的代码,希望它对您有用。

        [OperationContract]
        [WebGet(ResponseFormat = WebMessageFormat.Json)]
        Product GetProduct(int ID);

public Product GetProduct(int ID)
        {
            TestStoreEntities entities = new TestStoreEntities();
            return entities.Products.FirstOrDefault(x => x.Id == ID);
        }

web.config

<connectionStrings><add name="TestStoreEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=10.157.18.36;initial catalog=TestStore;persist security info=True;user id=sa;password=123456;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /></connectionStrings></configuration>

结果。
enter image description here

请随时告诉我是否有什么可以帮忙的。

相关问题