通过邮递员到wcf接收邮寄请求

时间:2019-08-06 11:31:57

标签: c# asp.net rest wcf postman

我试图使用WCF接收来自Postman的XML [post]消息,我需要首先了解一些来自其余部分的数据类型,例如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”是唯一允许的根元素名称。

1 个答案:

答案 0 :(得分:0)

XmlEnity的类型无法在WCF中正确序列化和反序列化。我们最好使用强类型的数据,并使用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
随时让我知道是否有什么可以帮助您的。