使用 DataContractJsonSerializer,我能够得到 Json 字符串。
现在,我想将此 Json(名为“流”)转换为 XML。有什么办法不使用“[WebInvoke(ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Wrapped)]”?
服务
[OperationContract]
string JsonSerializeFromDatabase();
[OperationContract]
string XmlSerializeFromJson(string strJson);
客户端
WCFService.Service1Client client = new WCFService.Service1Client();
string stream = client.JsonSerializeFromDatabase();
string stream2 = client.XmlSerializeFromJson(stream);
div1.InnerText = stream2;
我目前拥有的服务器端(但没有运气)
public string XmlSerializeFromJson(string strJson)
{
Stream stream1 = new FileStream("temp.xml", FileMode.Create);
XmlWriter xmlWriter = XmlWriter.Create(stream1);
XmlSerializerser = new XmlSerializer(typeof(string));
ser.Serialize(xmlWriter, strJson);
stream1.Position = 0;
StreamReader sr = new StreamReader(stream1);
string strXml = sr.ReadToEnd();
stream1.Dispose();
stream1.Close();
return strXml;
}