【问题标题】:receiving post request through postman into wcf通过邮递员将帖子请求接收到 wcf
【发布时间】:2019-12-13 22:48:41
【问题描述】:

我正在尝试使用 WCF 接收来自 Postman 的 XML [post] 消息,我首先需要了解一些来自 rest 的数据类型,例如 Stream、XML、HttpRequest。
我构建了这个简单的接收器,但到目前为止它无法正常工作。

    [WebInvoke(UriTemplate = "/PostMessage", Method = "POST")]
    public String InsertMessage(XmlEntity value)
    {
        String re = null;
        foreach (XmlNode node in value.ChildNodes)
        {
            string text = node.InnerText; 
            string tag = node.Name;

        }
    re = text;
  }

如果 Postman 将 Post 发送到我的项目,我的方法不会变成 get 类型吗?

如何访问 xml 请求中的每个标签及其各自的值?

邮递员向我发送此错误 400 遇到无效的根元素名称“消息”。 'root' 是唯一允许的根元素名称。

【问题讨论】:

    标签: c# asp.net rest wcf postman


    【解决方案1】:

    无法在 WCF 中正确序列化和反序列化 XmlEnity 的类型。我们最好使用强类型数据,并用 DataContract 属性装饰自定义类。
    https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/using-data-contracts
    SOAP 消息中的 XML 和 JSON 数据格式由 WCF 框架本身实现。

        [WebInvoke(Method = "POST",
      ResponseFormat = WebMessageFormat.Xml,
       RequestFormat = WebMessageFormat.Xml,
      BodyStyle = WebMessageBodyStyle.WrappedRequest,
            UriTemplate ="BookInfo/")]
    

    请参考回复中的例子。
    Get the object is null using JSON in WCF Service
    如果有什么可以帮助的,请随时告诉我。

    【讨论】:

      猜你喜欢
      • 2017-09-06
      • 2021-05-23
      • 2017-06-17
      • 2019-04-02
      • 2021-04-29
      • 1970-01-01
      • 2020-01-30
      • 1970-01-01
      • 2018-10-07
      相关资源
      最近更新 更多