发送列表<xmldocument>到wcf,怎么做?

时间:2016-07-25 06:53:01

标签: c# xml wcf

我试图将List发送给wcf。 我想把它作为json发送,有办法吗?

当我尝试序列化时,我得到空字符串,为什么?

public string ImportXml(List<XmlDocument> docs,string token)
        {
            Account user =  GetCurrentUser(token);
            string url = string.Format("{0}ImportXml/{1}", ServiceUrl, user.Unumber);
            string contentType = "text/json";
            x.Serialize(Console.Out, docs);
            string jsonReq = _serializer.Serialize(docs);
            bool response = false;
            HttpRequestHandler handler = new HttpRequestHandler();
            string result = handler.HttpPostWithToken(url, jsonReq, contentType, token);
            return result ; 
        }

2 个答案:

答案 0 :(得分:0)

在发送到WCF之前,集合文档的每个元素都必须以这种方式序列化为JSON:

string jsonText = JsonConvert.SerializeXmlNode(doc);

其中doc是XmlDocument。

或者以这种方式使用Javascript:Converting between XML and JSON

将XmlDocument收集到WCF方法后,尝试转换入口集合的每个元素:

var documents = new  List<XmlDocument>();

foreach (var doc in docs)
{
  XmlDocument xmlDoc = JsonConvert.DeserializeXmlNode(doc);
  documents.Add(xmlDoc);
}

答案 1 :(得分:0)

最后我得到了包含xml的字符串列表。

它好多了,因为我们可以与任何人合作,而不仅仅是C#。

然后我搬到了newtonsoft而不是JSS。

List<string>