【问题标题】:How to fix request error for a POST in postman app when there is no input?没有输入时,如何修复邮递员应用程序中 POST 的请求错误?
【发布时间】:2019-03-19 04:44:17
【问题描述】:

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

下面的 API 是一个 POST Api,它不接受任何输入但返回一个 json 响应。因此我在邮递员中以这种方式发送数据,但我总是收到这个错误。无法理解是什么问题。

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

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

谁能告诉我这是什么问题??

【问题讨论】:

    标签: rest wcf postman


    【解决方案1】:

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

            [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>
    

    结果。

    如果有什么我可以帮忙的,请随时告诉我。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-12-30
      • 1970-01-01
      • 2020-08-10
      • 1970-01-01
      • 2021-12-14
      • 2018-07-22
      • 2019-07-21
      相关资源
      最近更新 更多