C#序列化问题

时间:2014-09-15 13:56:32

标签: c# .net xml string serialization

我创建了一个通用方法来序列化包含soap请求/响应信息的对象以保存在sql表中。出于某种原因,<>似乎存储为&lt;&gt;

这是方法,

        public static void webServiceLogging<T>(T obj,
                            string messageType, string messageAction, string messageXML, RemoteEndpointMessageProperty endpoint)
    {
        OperationContext context = OperationContext.Current;
        MessageProperties messageProperties = context.IncomingMessageProperties;

        XmlSerializer serializer = new XmlSerializer(typeof(T));
        StringWriter writer = new StringWriter();
        serializer.Serialize(writer, obj);

        WebServiceLog serviceLog = new WebServiceLog();
        string payloadXml = serviceLog.MessageBody = writer.ToString();
        payloadXml = payloadXml.Replace(payloadXml.Substring(0, payloadXml.IndexOf("?>") + 2), "");
        serviceLog.MessageType = messageType;
        serviceLog.MessageAction = messageAction;
        serviceLog.MessageXml = messageXML;
        serviceLog.SenderIpAddress = endpoint.Address;
        serviceLog.MessageIdentifier = endpoint.Port.ToString();
        serviceLog.MessageBody = string.Format(payloadXml);
        SubmitWebServiceLog(serviceLog);

    }

我可能做错了什么?

0 个答案:

没有答案